-
File scan not working
I want this program to scan a text file (given as an argument) and just put the alpha characters it finds. Why isn't it working? Thanks!
Code:
#include <stdio.h>
#include <ctype.h>
int main(int argc, char *argv[])
{
int ch;
FILE *input = NULL;
if(!(input = fopen(argv[1], "r"))) {
printf("Error opening file!\n");
return 1;
}
while(ch = fgetc(input) != EOF) {
if(isalpha(ch))
putchar(ch);
}
return 0;
}
-
You've written this
while(ch = (fgetc(input) != EOF))
You want this
while((ch = fgetc(input)) != EOF)
Note the use of ( )
-
-
Well that program works fine to me!! may be place a getchar before the return 0.
EDIT: Perhaps, I did place the brakets when i tested that code. But dint mentioned it here lol. YES you need to brakets!
ssharish