请问各位大神,这是咋回事?这图片中的四行代码没错啊!
本帖最后由 张kk 于 2020-4-16 17:27 编辑#include <io.h>
#include <direct.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define MAX 256
long total;
int countLines(const char *filename);
void findAIICodes(const char *path);
void findALLFiles(const char *path);
int countiLines(const char *filename)
{
FILE *fp;
int count = 0;
int temp;
if ((fp = fopen(filename,"r")) == NULL)
{
fprintf(stderr, "Can not open the file: %,s\n", filename);
return 0;
}
while ((temp = fgetc(fp)) != EOF)
{
if (temp == '\n')
{
count++;
}
}
fclose(fp);
return count;
}
void findAIICodes(const char *path)
{
struct _finddata_t fa;
long handle;
char thepath, target;
strcpy(thepath, path);
if((handle = _findfirst(strcat(thepath, "/*.c"),&fa))!= -1L)
{
do
{
sprintf(target, "%s/%s",path, fa.name);
total += countLines(target);
}while (_findnext(handle, &fa) == 0);
}
_findclose(handle);
}
void findALLDirs(const char *path)
{
struct _finddata_t fa;
long handle;
char thepath;
strcpy(thePath, path);
if((handle = _findfirst(strcat(thepath, "/*"), &fa)) == -1L)
{
fprintf(stderr, "The path %s is wrong!\n",path);
return;
}
do
{
if (!strcmp(fa.name, ".") || !strcmp(fa.name, ".."))
continue;
if( fa.attrib == _A_SUBDIR)
{
sprintf(thepath, "%s/%s", path, fa.name);
findAIICodes(thepath);
findALLDirs(thePath);
}
}while (_findnext(handle, &fa) == 0);
_findclose(handle);
}
int main()
{
char path = ".";
printf("计算中...\n");
findAllCodes(path);
findALLDirs(path);
printf("目前你总共写了 %ld 行代码! \n\n", total);
system("pause");
return 0;
}file:///C:/Users/Administrator/Desktop/IMG_20200416_170823.jpg 看不见图片 这个没有显示图片
下面有链接 看不见图片。。。不要发本地图片链接 本帖最后由 XYcarpenter 于 2020-4-16 18:55 编辑
fprintf(stderr, "Can not open the file: %,s\n", filename);
为什么这句中的%和s之间有个逗号???
这个课后作业是Linux 和 MacOS的,你不要在Windows上运行 file 链接,太秀了
页:
[1]