both together ?
Printable View
both together ?
yes, read each line using fgets() in a loop (see the FAQ). And parsing the line you just read using sscanf() into your struct, make sure 'i' doesn't go out-of-bounds!
hm ... i am still doin sometin wrong ...its runnin but givin me garbage outCode:while(fgets(string,24,fp) != NULL);
(
sscanf(fp, "%d %d %d %d %d %d ", &(s[1].nr), &(s[1].d), &(s[1].s1), &(s[1].s2), &(s[1].s3), &(s[1].s4)));
}
> while(fgets(string,24,fp) != NULL);
That ; terminates the while loop - it does nothing for the whole file.
Also, do you have
char string[24];
or did you just declare
char *string;
and pray?
> sscanf(fp, "%d %d %d %d %d %d ", &(
You're using sscanf - scan from a string.
The first parameter is a FILE* pointer, not a pointer to a string. Didn't your compiler warn you, or did you just ignore it?
The usage is
sscanf( string, "formats", params );
ii counted 23 chars in my tablke above ... i rear that it has to be char+1 ... hence 24 ...
wpuld be very thankful if someone suggested the code !
it should be sizeof(string),
ie
Take the time to type slower, and make your exact problem clear ;)Code:char string[512];
while(fgets(string, sizeof(string), fp) != NULL)
{
/* ... */
thank u guys !
"%d %d %d %d %d %d "
Still not updated the format to the correct one?
no i did it now :-)