472,961 Members | 2,136 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,961 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 6206
weaknessforcats
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;
}
}
System.out.println(result);
}
catch (NumberFormatException e) {
System.exit(0);
}
catch (IOException e) {
e.printStackTrace();
System.exit(1);
}
}
while (true);
}
}
Mar 20 '08 #4
weaknessforcats
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

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

Similar topics

1
by: Swarup | last post by:
I am reading a file (txt, xml, gif, ico, bmp etc) byte by byte and filling it into a byte arry. Now i have to convert it into a string to store it in the database. I use...
7
by: whatluo | last post by:
Hi, all I'm now working on a program which will convert dec number to hex and oct and bin respectively, I've checked the clc but with no luck, so can anybody give me a hit how to make this done...
2
by: Joey Lee | last post by:
Hi, Does anyone know how I am able to write a utf-8 encoded binary string into binary file? Currently I am given a UTF-8 string which was read from a gif image. Here are my functions... ...
6
by: as400tips | last post by:
I have a Binary Data file (Packed Decimal and ASCII mixed) and would like to convert into ASCII (readable) file. How to do it in C#? Thanks.
0
by: Andy | last post by:
Hi, I have a MS Word binary data file that is sent from my .NET webservice in response to an XMLHTTP request from an Internet Explorer client. This data has to be base64 encoded to tunnel through...
7
by: elliotng.ee | last post by:
I have a text file that contains a header 32-bit binary. For example, the text file could be: %%This is the input text %%test.txt Date: Tue Dec 26 14:03:35 2006...
29
by: Harlin Seritt | last post by:
Hi... I would like to take a string like 'supercalifragilisticexpialidocius' and write it to a file in binary forms -- this way a user cannot read the string in case they were try to open in...
5
by: sweeet_addiction16 | last post by:
im coding in c....i need to accept an integer value(decimal) and then after converting it into hexadecimal value i need to write it into a file.i do not need to print it..so using fprintf along...
22
by: xiao | last post by:
Can I fullfill this task? Using fred and fwrite?
1
by: Man4ish | last post by:
I have sent one thread about the use of binary file for file indexing and got some very good reply and which helped me a lot. Now I am proceeding ahead. But facing one pblm of converting text file...
0
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
2
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 4 Oct 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
tracyyun
by: tracyyun | last post by:
Hello everyone, I have a question and would like some advice on network connectivity. I have one computer connected to my router via WiFi, but I have two other computers that I want to be able to...
2
by: giovanniandrean | last post by:
The energy model is structured as follows and uses excel sheets to give input data: 1-Utility.py contains all the functions needed to calculate the variables and other minor things (mentions...
4
NeoPa
by: NeoPa | last post by:
Hello everyone. I find myself stuck trying to find the VBA way to get Access to create a PDF of the currently-selected (and open) object (Form or Report). I know it can be done by selecting :...
1
by: Teri B | last post by:
Hi, I have created a sub-form Roles. In my course form the user selects the roles assigned to the course. 0ne-to-many. One course many roles. Then I created a report based on the Course form and...
0
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be focusing on the Report (clsReport) class. This simply handles making the calling Form invisible until all of the Reports opened by it have been closed, when it...
0
isladogs
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...

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.