I am trying to scan in this information:
00abcabc:abc123
01defdef:def456
02hijhij:hij789
into two arrays using this code:
FILE *dataLogin;
int i=0, numRecords;
char username[100][10], password[100][10];
dataLogin = fopen("login.dat", "r");
if (dataLogin == NULL){printf("Error");}
else {
while (fscanf(dataLogin, "%s:%s\n", username[i], password[i])){i++;}
fclose(dataLogin);
numRecords = i;
for(i = 0; i < numRecords; i++){printf("%s, %s\n", username[i], password[i]);}
}
printf("complete");
The program compiles and runs but doesn't display anything. I believe I have isolated the fault to the while loop but I am stuck from there. Thanks!
fscanfwhilecondition to verify that it returns 2, eg.(fscanf(...) == 2)rather than just(fscanf(...)). That'll only succeed if you read 2 strings.