#include <stdio.h>
#include <string.h>
int main()
{
int count = 0;
char *doc;
FILE *inp;
printf("Enter the file name: ");
scanf("%s", doc);
inp=fopen(doc, "r");
while((doc = fgetc(doc)) != EOF)
{
if (doc == ' ')
count++;
}
fclose(doc);
printf("%s contains %d words\n",doc,count);
return 0;
}
So basically I'm a little bit confused. I believe the logic of my program is correct; file pointer is declared, and I do have a character to store my array, it reads the file, and counts all the words pending a space in front/between/etc. Basically the program should ask the used the used to input the name of the file they're scanning. The file opens and goes through the program and outputs a line that tells the user the # of words in the file that was inputted.
My problem has been compiling it.
I'm getting this:
wordcount.c: In function ‘main’:
wordcount.c:13:5: warning: passing argument 1 of ‘fopen’ makes pointer from integer without a cast [enabled by default]
/usr/include/stdio.h:271:14: note: expected ‘const char * __restrict__’ but argument is of type ‘char’
wordcount.c:15:5: warning: passing argument 1 of ‘fgetc’ makes pointer from integer without a cast [enabled by default]
/usr/include/stdio.h:535:12: note: expected ‘struct FILE *’ but argument is of type ‘char’
wordcount.c:21:5: warning: passing argument 1 of ‘fclose’ makes pointer from integer without a cast [enabled by default]
/usr/include/stdio.h:236:12: note: expected ‘struct FILE *’ but argument is of type ‘char’