convert the text file to a binary file

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • chelle2100
    New Member
    • Mar 2008
    • 6

    convert the text file to a binary file

    hi... i need to write a converter to convert the text file to a binary file with the following file format...

    CharacterCount: Unsigned Char(This stores the number of characters that is in the file)
    Name:Char[256](An array of 256 char that stores the name of the character. You will need to prompt the user if the name given in the text file is longer than the maximum length it can hold)
    Weapon:Unsigned Short(Uses a single 16bit data type to store the weapon that is valid for the character. )The value are predefined as such

    Knife 1
    Shotgun 2
    Machinegun 4
    Grenade 8
    Flashbang 16
    Mine 32

    Life:Unsigned char(A single unsigned char value that stores the health point value of the character)
    MovingSpeed:flo at(A single float value that stores the moving speed of the character)
  • weaknessforcats
    Recognized Expert Expert
    • Mar 2007
    • 9214

    #2
    Please read the posting guidelines.


    I can help with specific programming and design issues but I cannot provide complete solutions or act as a tutor.

    Comment

    • chelle2100
      New Member
      • Mar 2008
      • 6

      #3
      i just need guides to go along programming it.. like how should i start... i'm not looking for answers... I've nv use C++ before and that's de problem...

      Comment

      • chelle2100
        New Member
        • Mar 2008
        • 6

        #4
        ok... this is wat i gone so far... but this code i did in java not C++... and is tt the user keys in a no then it's change to binary.. wat i need is a txt file with extension .cha to a binary file with extension .chb

        import java.io.*;

        public class TexttoBinary {
        private static final int maxBytes = 3;
        public static void main(String[] args) {

        BufferedReader in = new BufferedReader( new InputStreamRead er(System.in));
        do {
        try {
        System.out.prin t("Type the number to parse: ");
        int number = Integer.parseIn t(in.readLine() );
        int Bit;
        String result = "";
        for (int i = maxBytes*8; i >= 0; i--) {
        Bit = 1 << i;
        if (number >= Bit) {
        result += 1;
        number -= Bit;
        }
        else {
        result += 0;
        }
        }
        System.out.prin tln(result);
        }
        catch (NumberFormatEx ception e) {
        System.exit(0);
        }
        catch (IOException e) {
        e.printStackTra ce();
        System.exit(1);
        }
        }
        while (true);
        }
        }

        Comment

        • weaknessforcats
          Recognized Expert Expert
          • Mar 2007
          • 9214

          #5
          All of this is in any C++ textbook.

          Try the C++ Primer Plus 5th Ed by Stephen Prata. All of the info you need is in there.

          Comment

          • chelle2100
            New Member
            • Mar 2008
            • 6

            #6
            thank you very much... uR help is needed very badly

            Comment

            • chelle2100
              New Member
              • Mar 2008
              • 6

              #7
              sorry but any other books to recommend????

              Comment

              • chelle2100
                New Member
                • Mar 2008
                • 6

                #8
                just to clarify, the bks guides us to convert from .cha to .chb???
                n wat's .cha??? wat's .chb???

                Comment

                Working...