P
philbo30
Newbie here, just need a little general C direction:
I've a function that counts text lines in a file. If the file contains
less than 1000 lines of text, I know my input is garbage and I need
the app to completely stop all further processing. Currently, the
counting and evaluation works fine, but my app keeps on processing.
Here's the code I have so far:
int inputcheck()
{
file *fp;
int linecounter = 0;
int ch;
fp = fopen("hooligans.txt","r");
if (fp==NULL)
{
perror("fopen");
return EXIT_FAILURE;
}
while ((ch= getc(fp)) !=EOF)
{
if (ch == '\n') linecounter++;
}
fclose(fp);
if (linecounter < 1000)
{
printf("Garbage In, Don't Continue Processing\n"); //NEED TO STOP
ALL PROCESSING IF HERE
return -1;
}
else
return 0;
}
}
I've a function that counts text lines in a file. If the file contains
less than 1000 lines of text, I know my input is garbage and I need
the app to completely stop all further processing. Currently, the
counting and evaluation works fine, but my app keeps on processing.
Here's the code I have so far:
int inputcheck()
{
file *fp;
int linecounter = 0;
int ch;
fp = fopen("hooligans.txt","r");
if (fp==NULL)
{
perror("fopen");
return EXIT_FAILURE;
}
while ((ch= getc(fp)) !=EOF)
{
if (ch == '\n') linecounter++;
}
fclose(fp);
if (linecounter < 1000)
{
printf("Garbage In, Don't Continue Processing\n"); //NEED TO STOP
ALL PROCESSING IF HERE
return -1;
}
else
return 0;
}
}