J> i save a digit lets say is 6542 to a file ( XXX.ext )
J> how would i read the digit in XXX.ext and +/- from it?
J> HELP!
J> i save it fprintf("fptr, %d", total);
^ ^ Move the quote to after fptr,
J> i tried but it reads the contents of the file as a string!?
This will "save" (print) the total as a string, which is what %d is supposed
to do. What you seem to want is:
fwrite(&total, sizeof(total), 1, fptr);
To read this in:
fread(&total, sizeof(total), 1, fptr);
J> and i cant add # to a string. Is there a way to convert a string -> int?
J> or read a file as int?
Your way:
fscanf(fptr, "%d", &total);
However, I recommend getting it as a string (look up fgets in your C
documentation, and get the entire line) and then parsing it manually.
Note that string -> int functions abound. Personally, I usually use strtol
or strtoul.
HTH,
Jabo,
This is a real name only echo. Please use your real name in the "From"
field. Until your sysop changes this, please sign your messages with your
real name. Thanks,
Darin McBride
C_PLUSPLUS echo moderator
---
---------------
* Origin: Tanktalus' Tower BBS (1:250/102)
|