test.c scans file.txt and prints name for a given id.
I would like to add a 3rd column to file.txt
I also would like to ask:
what does %99s
and == 2
mean in:
while (fscanf(fff, "%d %99s", &id, name) == 2) {
file.txt ( new column added )
1 name1 newcolumn1
2 name2 newcolumn2
3 name3 newcolumn3
test.c modified to work with 3rd column ( added char name2[100]; and cloned %99s )
Result: Not Working. ( compiles: ok. but outputs empty (nothing) )
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
main() {
char name[100];
char name2[100];
FILE *fff;
int found = 0;
int id;
fff = fopen("/file.txt", "r");
while (fscanf(fff, "%d %99s %99s", &id, name, name2) == 2) {
if (id == 2) {
printf("%s\n", name2);
found = 1;
break;
}
}
fclose(fff);
return 0;
}