- Joined
- Nov 30, 2007
- Messages
- 1,202
PHP:
int loadFile(char* file, Match match[], int* indexMax)
{
int d;
system("cls");
printf("Enter File (FileName.txt) : ");
getStringNoSpace(file);
d = strlen(file);
if (d > 4 && file[d-4] == '.' && file[d-3] == 't' && file[d-2] == 'x' && file[d-1] == 't') {
char s1[STRLEN], s2[STRLEN], s3[STRLEN], s4[STRLEN];
FILE *fp;
fp = fopen(file,"r");
if (fp != NULL) {
while (fscanf(fp, "%s %s %s %s", s1, s2, s3, s4) == 4) {
if (createMatch(&match[*indexMax], s1, s2, s3, s4)) {
(*indexMax)++;
printf("Loaded game %d from %s...\n", *indexMax, file);
}
else {
printf("Failed to load line %d from file %s!!!\n", *indexMax + 1, file);
}
}
}
}
pressAnyKey();
}
Basicially I want to discard every row that finds invalid entries. The following will be printed:
PHP:
printf("Failed to load line %d from file %s!!!\n", *indexMax + 1, file);
The only issue I'm having is that every row after that also becomes invalid. I belieave it's because everything in the scan gets "dislodged" or done in the wrong order I would like to not re-scan or what ever is going on...
Any ideas?
The text file looks like this:
2014-07-30 GFF NOR 1-2
2013-02-29 GFF MAIF 1-3 <<< this causes a friendly error. It doesn't read because that date I reckon doesn't exist.
2014-03-06 GFF HBK 1-2
2014-03-06 GFF HELLO HBK 1-2 <<<< this break the logic of the scanf == 4 and thus every file afterwards is broken.
and an example of an error would be to add spaces to any of the entries...
Last edited: