r/C_Homework • u/ApartRapier6491 • Nov 04 '19
C scanf help
Hey, so there is this file for me to scan each line.
- Each line may contain a name and number. If the line starts with '/' then this line should be skipped.
- If the line contains name and number then it still may contain '/' after number, then it should ignore everything from that character to the end of line.
I have tried
char name[BUFLEN];
int value;
while ( fscanf( fp, "%s %d %*[^/]", name, &value ) != EOF ) {
printf( "%s %d\n", name, value );
}But it doesn't work and even then it only does second case. How can I indicate that name and value are optional and that '/' may or may not be presented?
Sorry, but C I/O is such weird to me and I struggle to get it right. Help?
1
Upvotes
View all comments
Show parent comment
1
u/ApartRapier6491 Nov 08 '19
Thanks!