编译问题
#include<io.h>#include<直接.h>
#include<stdio.h>
#include<stdlib.h>
#include<字符串.h>
#define 最大 256
长总计;
int countLines(const char *filename);
void findAllCodes(const char *path);
void findALLFiles(const char *path);
int countLines(const char *filename)
{
文件 *fp;
整数计数=0;
整数温度;
if ((fp=fopen(文件名, "r"))==NULL)
{
fprintf(stderr, "无法打开文件:%s\n", 文件名);
返回 0;
}
而((temp=faetc(fp))!=EOF)
{
if (temp=='\n')
{
计数++;
}
}
FCLOSE(FP);
返回计数;
}
void findAllCodes(const char *path)
{
结构_finddata_t FA;
长手柄;
char thePath, target;
strcpy(thePath, path);
if ((handle=_findfirst(strcat(thePath, "/*.c"), &fa))!=-1L)
{
做
{
sprintf(target, "%s/%s", path, fa.name);
总计+=计数行(目标);
}while (_findnext(handle, &fa)== 0);
}
_findclose(手柄);
}
void findALLDirs(const char *path)
{
结构_finddata_t FA;
长手柄;
char thePath;
strcpy(thePath,path);
if ((handle=_findfirst(strcat(thePath, "/*"), &fa)) == -1L)
{
fprintf(stderr, "the path %s is wrong!\n", path);
返回;
}
做
{
if (!strcmp(fa.name, “.”) || !strcmp(fa.name, “..”))
继续;
if ( fa.attrib == _A_SUBDIR)
{
sprintf(thePath, "%s/%s", path, fa.name);
查找所有代码(路径);
findALLDirs(thePath);
}
}while (_findnext(handle, &fa)==0);
_findclose(手柄);
}
int main()
{
字符路径 =".";
printf("计算中...\n");
查找所有代码(路径);
findALLDirs(path);
printf("目前你总共写了%1d行代码!\n\n", total);
系统("暂停");
返回 0;
}
本强迫症患者照着鱼c的代码抄的,为啥到第二行 #include<直接.h> 就编译错误 快把您的网页翻译关一关罢 <直接.h> 发现没 它是中文,所以C语言不认识中文,于是它果断报错了
正确的应该是这样:(温馨提示:抄自己编译器对应的版本的代码)
Windows:版本
#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 findAllCodes(const char *path);
void findALLFiles(const char *path);
int countLines(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 findAllCodes(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);
findAllCodes(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;
}
Linux 和 MacOS:
#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 findAllCodes(const char *path);
void findALLFiles(const char *path);
int countLines(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 findAllCodes(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);
findAllCodes(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;
} {:10_250:} 做最好的自己520 发表于 2023-2-15 17:44
发现没 它是中文,所以C语言不认识中文,于是它果断报错了
正确的应该是这样:(温馨提示:抄自己编译器 ...
《C语言不认识中文》
《计算中》
《目前你总共写了 %ld 行代码!》 dolly_yos2 发表于 2023-2-14 21:44
快把您的网页翻译关一关罢
谢谢{:10_266:} dolly_yos2 发表于 2023-2-15 18:40
《C语言不认识中文》
《计算中》
《目前你总共写了 %ld 行代码!》
{:10_315:} 爱学习的浩浩 发表于 2023-2-15 20:05
谢谢
没事没事,加油,慢慢来才会快!{:10_265:}
如果你的问题已解决,请设置最佳答案
页:
[1]