471,049 Members | 1,409 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,049 software developers and data experts.

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:float(A single float value that stores the moving speed of the character)
Mar 19 '08 #1
7 5999
9,208 Expert Mod 8TB
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.
Mar 19 '08 #2
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...
Mar 20 '08 #3
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 InputStreamReader(System.in));
do {
try {
System.out.print("Type the number to parse: ");
int number = Integer.parseInt(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;
catch (NumberFormatException e) {
catch (IOException e) {
while (true);
Mar 20 '08 #4
9,208 Expert Mod 8TB
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.
Mar 20 '08 #5
thank you very much... uR help is needed very badly
Mar 21 '08 #6
sorry but any other books to recommend????
Mar 21 '08 #7
just to clarify, the bks guides us to convert from .cha to .chb???
n wat's .cha??? wat's .chb???
Mar 21 '08 #8

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

1 post views Thread by Swarup | last post: by
2 posts views Thread by Joey Lee | last post: by
6 posts views Thread by as400tips | last post: by
7 posts views Thread by elliotng.ee | last post: by
29 posts views Thread by Harlin Seritt | last post: by
5 posts views Thread by sweeet_addiction16 | last post: by
22 posts views Thread by xiao | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.