Hi all,
Am trying to write some code that will read a simple text file and return what is placed in the text file along with how many characters there are. Reading the file works but am having a problem with the correct number of characters, keeps on saying minus 1. If anyone could help i would be very grateful. Thanks in advance.
#include<stdio.h>
int main(void)
{
FILE * input_file;
char input_filename[20];
char file[20];
int rval, ch;
printf("Please input the file name you wish to open: ");
scanf("%s", input_filename);
input_file=fopen(input_filename,"r");
rval=fscanf(input_file,"%s",file);
printf("%s\n",file);
while((fgetc(input_file))!=EOF);
{
ch=fgetc(input_file);
printf("%d characters in file.\n", EOF);
}
fclose(input_file);
return 0;
}