【发布时间】:2013-12-12 02:57:49
【问题描述】:
我目前正在尝试仅读取和处理“.c”文件每行中的第一个字符。到目前为止,我已经找到了这段代码,但 n 甚至没有在循环中打印出来:
void FileProcess(char* FilePath)
{
char mystring [100];
FILE* pFile;
int upper = 0;
int lower = 0;
char c;
int n =0;
pFile = fopen (FilePath , "r");
do {
c = fgetc (pFile);
if (isupper(c)) n++;
} while (c != EOF);
printf("6");
printf(n);
fclose (pFile);
}
【问题讨论】:
-
您的意思是
printf("%d\n", n);吗? (顺便说一句,编译器应该警告你当前的代码) -
该循环不会读取每一行的第一个字符,它会读取文件中的 每个 字符。您可能想使用例如
fgets将一行读入缓冲区,然后从该缓冲区中获取第一个字符。