我试图编写一个程序来计算从文件中获取的文本中的单词数。我有一个问题,编译器找不到我的文件,但是我把这个文件放在项目文件夹中。我能做些什么?
#include <stdio.h>
#include <conio.h>
#include <string.h>
int words(const char sentence[ ]);
int main(void) {
char sentence[100];
FILE *cfPtr;
if ( (cfPtr = fopen("C programming.dat", "r")) == NULL ) {
printf( "File could not be opened\n" );
}
else {
fscanf(cfPtr, "%s", sentence);
}
words(sentence);
printf("%d", words(sentence));
getch();
return 0;
}
int words(const char sentence[ ]) {
int i, length = 0, count = 0, last = 0;
length = strlen(sentence);
for (i = 0; i < length; i++)
if (sentence[i] == ' ' || sentence[i] == '\t' || sentence[i] == '\n')
count++;
return count;
}