So something really weird is happening to my program for number 1. It compiles without warning but for some reason the filename gets changed to whatever string the function was counting so for the final print statement it prints "(whatever last string was in file) contains (however many words were in the file)" .. Anyone have any idea why?
insert
Code:
#include<stdio.h>
#include<string.h>
int main()
{
FILE *fp;
char f_name[64];
char status;
int count = 0;
char x;
printf("Enter the file name: ");
scanf("%s", f_name);
printf("%s\n", f_name);
fp = fopen (f_name, "r");
do
{
x = fscanf(fp,"%s", &x);
status = x;
if (status != EOF)
{
count++;
printf("%s\n", f_name);
}
}
while ( status != EOF );
printf("%s contains %d words.\n", f_name, count);
return 0;
}