I'm a beginner for C programming. For a part of my project, I have to take an input file from the user and be able to print it onto the screen. This is what I have so far:
However... I don't think the while loop is working properly especially when I get an argument error. How can I fix this?
Thanks!
Code:
char filename[10];
FILE *ifp;
printf("Enter the name of the file to analyze :");
scanf("%s", filename);
printf("\n");
ifp = fopen(filename, "r");
if (ifp == NULL)
{
fprintf(stderr, "Could not open file: '%s' ", filename);
exit (-1);
}
int c = fgetc(ifp);
while (c != EOF)
{
printf("%c", ifp);
}
fclose(ifp);
Thanks!
Comment