a question files

This is a discussion on a question files within the C++ Programming forums, part of the General Programming Boards category; hi ppl
i want someone please to answer me!
how can write a data such as ( 0.7) to a ...

how can write a data such as ( 0.7) to a file in a size which is smallest
that is not a float , i want the least size that i can

I understand your question, but I don't know the answer. A float can hold from 1.2 x 10exp-23 to 3.4x10exp38, and all you want to store is a little .7 without wasting all those extra bits. I'm sure someone here will be able to tell you how to do that.

if i write to a file the ascii of a number and i want to read it from the file ,will the c++ program understand it as the original number
ex:
putc(myfile,56);

if i want to do
getc(myfile);
will the received char be the 56 ??????

First, it looks like you have your arguments backwards:

Code:

int putc( int ch, FILE *stream );

When I try this:

putc(56, file1);

It writes an 8 to file1. When I try this:

char ch = getc(file1);

and then display it to the console window, I get an 8. But, I believe the act of displaying it, converts the ASCII 56 in the variable to an 8.

Since an ASCII 56 produces an 8 in the file, I can set up a test. I will write 56 to file1, close file1, open file1, then do this:

char ch;
getc(ch, file1);

I won't know what is in ch at this point. But, if I write ch to a second file, and it produces an 8, then I will have this situation:

putc(56, file1)----->8
putc(ch, file2)----->8

and that can only mean that ch is ASCII 56. Here goes...................there is an 8 in both files.

I think the lesson is: with a char type, C++ will convert the ascii number stored in the variable to the character whenever you try to display it, whether in a file or in the console window. If you want to actually see the ascii code, you need to convert the char variable to an int.