in content():
Code:
input_file=fopen(input_filename, "r");
rval=fscanf(input_file, "%s", file);
First check if fopen failed, then read from file.
After you have called this function (content()) the file pointer (input_file) is pointing to the second string (and not the beginning of the file). You need to reposition the filepointer before calling characters().
Code:
content();
fseek(input_file, 0, SEEK_SET); /* reposition filepointer to beginning of file */
characters();
In characters():
Code:
while((temp=fgetc(input_file)) != EOF)
{
ch++;
}
Another option is to combine the 2 functions into 1:
Code:
void characters()
{
char ch;
int count = 0;
printf("The file contains the following text:\n");
while((ch = fgetc(fp)) != EOF)
{
printf("%c", ch);
count++;
}
printf("Number of characters = %d\n", count);
}