reading file problem
i am making a program to get familiar with writing and reading files,this program is to write the time that lets say an employee comes to work and what time she checks out ,and only executes twice a day.
i have a problem with my code ,
i want to create a file and to write to it sequentially.
the info to write is the date format and local time,that it will write to file every time we execute the program in WM_CREATE msg.
static int ,i, j, k, l;
static char a, s,
GetDate//Format(//////////////////&st, a, ////////)
Here i stored the value for date format which is like:
"tuesday, january, 14 2003" in array a and start writing the info in file name time.dat:
fopen = ,,,,,(pfile , "time.dat"//////);
fprintf(pfile, "%s%d%d%d\n", a, st.wHour, st.wMinute, st.wSecond);
up to here i check the file and the program writes to it Ok.
then in WM_PAINT i process reding the same file and go about it by:
fscanf(pfile, "%s%d%d%d", s, j, k, l);
sprintf(f, "%d%d%d", j, k, l);
here is the problem when i try reading the values with text out
what it shows on screen is like;
and leaves out the rest of the date format ,but if i use 4 arrays in fscanf instead of one like this:
fscanf(pfile, "%s%s%s%s%d%d%d", s, s1, s2, s3, j, k, l);
it shows the whole string. WHY? is it because it reads the space characters as null how do i skip them?www.cprogramming.com http\\www.cprog.com i have a problem iiiiiiiiiiiii [IMG]http://[/IMG] i want to
What the hell's going on there? :confused:
Pleasepleasepleasepleaseplease use [code][/code] tags!
With a cherry on top? :D
OK im sorry.
im simplifing for you with more detail;
static char s, a,;
first i created a sequential file "time.dat" then i used:
GetDateFormat(LOCAL_SYSTEM_DEFAULT, DATE_LONGDATE, &st,NULL, s, sizeof(s));
now the value: "wednesday, january, 15 2003"
is stored in array s fine.
i write it to file time.dat like this:
pfile = fopen("time.dat", "a+");
fprintf(pfile, "%s", s);
Again i check the file its fine info appears in the file as string s.
now i try to read it from the file as follows:
pfile = fopen("time.dat", "r")
fscanf(pfile, "%s", a);
TextOut(hdc, 0, 0, a, strlen(a));
now this time it reads it as:
"thursday" and nothing appear after thursday.
but if i initialize 4more arrays (a1 a2 a3 a4) and use fscanf like this:
fscanf(pfile, "%s%s%s%s", a, a1, a2, a3);
sprintf(a4, "%s%s%s%s", a, a1, a2, a3);
TextOut(hdc, 0, 0, a4, strlen(a4));
everything works fine as it should:
"wednesday, january, 15 2003"
i think the problem is fscanf is reading the space char as null how can i fix it so i can only be able 1 array for output?
i hope i was neat!
Code tags aren't particularly necessary with the small chunks that he's got (at least in his seocnd post)
try something like...(I think, anyhow - I haven't used scanf() or its variants in a while...)
fscanf(pfile, "%[^\n]", string);