新手求教
#include <io.h>
#include <direct.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#定义MAX 256
zongchang
int countLines(const char *wenjianming)
void findAllCodes(const char * path)
void findALLfiles(const char * path)
int countLines(const char *wenjianming)
{
wenjian*fp;
int count = 0:
wendu
ruguo((fp=fopen(wenjianming,"r"))==NULL)
{
fprintf(stderr,"无法打开文件;%s\n",wenjianming)
fanhui0;
}
er((temp = fgetc(fp))!=EOF)
{
ruguo(temp =='\ n')
{
shu++;
}
}
fclose(fp);
fanhuijishu;
}
无效findAllCodes(const char * path)
{
struct _finddata_t fa;
长柄
char thePath , target;
strcpy(thePath,path);
if((句柄=_findfirst(strcat(thePath,"/*.c"),&fa))! =1L)
{
做
{
sprintf(target,"%s /%s",path,fa.name);
总数+ =countLines(目标);
}
_findclose(handle);
}
无效findALLDirs(const char * path)
{
struct _finddata_t fa;
长柄
char thePath
strcpy(thePath,path);
if((句柄=_findfirst(strcat(thePath,"/*"),&fa))== -1L)
{
fprintf(stderr,"%s路径错误!\n",path);
返回;
}
做
{
if(!strcmp(fa.name,"。")ll!strcmp(fa.name,"..")))
继续;
if(fa.attrib ==_A_SUBDIR)
{
sprintf(thePath,"%s /%s",path,fa.name);
findallCodes(thePath);
findALLdirs(thePath);
}
}同时(_findnext(handle,&fa)== 0);
_findclose(handle);
}
int main()
{
char path ="。";
print("计算中...\n");
findAllCodes(path);
findALLDirs(path);
printf("目前你总共写了%ld行代码!\ n \ n",总计);
系统("暂停");
返回0;
}
}
按照小甲鱼发的课后作业 然后报错
8 2 C:\Users\快乐的青呀\Desktop\c语言\s1e2\hello world.c invalid preprocessing directive #?
12 1 C:\Users\快乐的青呀\Desktop\c语言\s1e2\hello world.c expected '=', ',', ';', 'asm' or '__attribute__' before 'int'
30 17 C:\Users\快乐的青呀\Desktop\c语言\s1e2\hello world.c unknown escape sequence: '\040'
30 17 C:\Users\快乐的青呀\Desktop\c语言\s1e2\hello world.c multi-character character constant [-Wmultichar]
41 1 C:\Users\快乐的青呀\Desktop\c语言\s1e2\hello world.c stray '\316' in program
41 1 C:\Users\快乐的青呀\Desktop\c语言\s1e2\hello world.c stray '\336' in program
41 1 C:\Users\快乐的青呀\Desktop\c语言\s1e2\hello world.c stray '\320' in program
41 1 C:\Users\快乐的青呀\Desktop\c语言\s1e2\hello world.c stray '\247' in program
C:\Users\快乐的青呀\Desktop\c语言\s1e2\hello world.c In function 'findAllCodes':
44 6 C:\Users\快乐的青呀\Desktop\c语言\s1e2\hello world.c stray '\263' in program
44 6 C:\Users\快乐的青呀\Desktop\c语言\s1e2\hello world.c stray '\244' in program
44 6 C:\Users\快乐的青呀\Desktop\c语言\s1e2\hello world.c stray '\261' in program
44 6 C:\Users\快乐的青呀\Desktop\c语言\s1e2\hello world.c stray '\372' in program
45 17 C:\Users\快乐的青呀\Desktop\c语言\s1e2\hello world.c 'MAX' undeclared (first use in this function)
45 17 C:\Users\快乐的青呀\Desktop\c语言\s1e2\hello world.c each undeclared identifier is reported only once for each function it appears in
48 3 C:\Users\快乐的青呀\Desktop\c语言\s1e2\hello world.c stray '\276' in program
48 3 C:\Users\快乐的青呀\Desktop\c语言\s1e2\hello world.c stray '\344' in program
48 3 C:\Users\快乐的青呀\Desktop\c语言\s1e2\hello world.c stray '\261' in program
48 3 C:\Users\快乐的青呀\Desktop\c语言\s1e2\hello world.c stray '\372' in program
48 11 C:\Users\快乐的青呀\Desktop\c语言\s1e2\hello world.c expected expression before '=' token
50 4 C:\Users\快乐的青呀\Desktop\c语言\s1e2\hello world.c stray '\327' in program
50 4 C:\Users\快乐的青呀\Desktop\c语言\s1e2\hello world.c stray '\366' in program
53 7 C:\Users\快乐的青呀\Desktop\c语言\s1e2\hello world.c stray '\327' in program
53 7 C:\Users\快乐的青呀\Desktop\c语言\s1e2\hello world.c stray '\334' in program
53 7 C:\Users\快乐的青呀\Desktop\c语言\s1e2\hello world.c stray '\312' in program
53 7 C:\Users\快乐的青呀\Desktop\c语言\s1e2\hello world.c stray '\375' in program
53 13 C:\Users\快乐的青呀\Desktop\c语言\s1e2\hello world.c expected expression before '=' token
53 13 C:\Users\快乐的青呀\Desktop\c语言\s1e2\hello world.c stray '\304' in program
53 13 C:\Users\快乐的青呀\Desktop\c语言\s1e2\hello world.c stray '\277' in program
53 13 C:\Users\快乐的青呀\Desktop\c语言\s1e2\hello world.c stray '\261' in program
53 13 C:\Users\快乐的青呀\Desktop\c语言\s1e2\hello world.c stray '\352' in program
57 15 C:\Users\快乐的青呀\Desktop\c语言\s1e2\hello world.c 'handle' undeclared (first use in this function)
60 2 C:\Users\快乐的青呀\Desktop\c语言\s1e2\hello world.c stray '\316' in program
60 2 C:\Users\快乐的青呀\Desktop\c语言\s1e2\hello world.c stray '\336' in program
60 2 C:\Users\快乐的青呀\Desktop\c语言\s1e2\hello world.c stray '\320' in program
60 2 C:\Users\快乐的青呀\Desktop\c语言\s1e2\hello world.c stray '\247' in program
60 18 C:\Users\快乐的青呀\Desktop\c语言\s1e2\hello world.c expected expression before 'const'
61 2 C:\Users\快乐的青呀\Desktop\c语言\s1e2\hello world.c expected ';' before '{' token
63 3 C:\Users\快乐的青呀\Desktop\c语言\s1e2\hello world.c stray '\263' in program
63 3 C:\Users\快乐的青呀\Desktop\c语言\s1e2\hello world.c stray '\244' in program
63 3 C:\Users\快乐的青呀\Desktop\c语言\s1e2\hello world.c stray '\261' in program
63 3 C:\Users\快乐的青呀\Desktop\c语言\s1e2\hello world.c stray '\372' in program
67 2 C:\Users\快乐的青呀\Desktop\c语言\s1e2\hello world.c stray '\276' in program
67 2 C:\Users\快乐的青呀\Desktop\c语言\s1e2\hello world.c stray '\344' in program
67 2 C:\Users\快乐的青呀\Desktop\c语言\s1e2\hello world.c stray '\261' in program
67 2 C:\Users\快乐的青呀\Desktop\c语言\s1e2\hello world.c stray '\372' in program
70 3 C:\Users\快乐的青呀\Desktop\c语言\s1e2\hello world.c stray '\267' in program
70 3 C:\Users\快乐的青呀\Desktop\c语言\s1e2\hello world.c stray '\265' in program
70 3 C:\Users\快乐的青呀\Desktop\c语言\s1e2\hello world.c stray '\273' in program
70 3 C:\Users\快乐的青呀\Desktop\c语言\s1e2\hello world.c stray '\330' in program
73 2 C:\Users\快乐的青呀\Desktop\c语言\s1e2\hello world.c stray '\327' in program
73 2 C:\Users\快乐的青呀\Desktop\c语言\s1e2\hello world.c stray '\366' in program
76 11 C:\Users\快乐的青呀\Desktop\c语言\s1e2\hello world.c stray '\274' in program
76 11 C:\Users\快乐的青呀\Desktop\c语言\s1e2\hello world.c stray '\314' in program
76 11 C:\Users\快乐的青呀\Desktop\c语言\s1e2\hello world.c stray '\320' in program
76 11 C:\Users\快乐的青呀\Desktop\c语言\s1e2\hello world.c stray '\370' in program
84 1 C:\Users\快乐的青呀\Desktop\c语言\s1e2\hello world.c stray '\315' in program
84 1 C:\Users\快乐的青呀\Desktop\c语言\s1e2\hello world.c stray '\254' in program
84 1 C:\Users\快乐的青呀\Desktop\c语言\s1e2\hello world.c stray '\312' in program
84 1 C:\Users\快乐的青呀\Desktop\c语言\s1e2\hello world.c stray '\261' in program
C:\Users\快乐的青呀\Desktop\c语言\s1e2\hello world.c In function 'main':
91 12 C:\Users\快乐的青呀\Desktop\c语言\s1e2\hello world.c 'MAX' undeclared (first use in this function)
98 9 C:\Users\快乐的青呀\Desktop\c语言\s1e2\hello world.c unknown escape sequence: '\040'
98 9 C:\Users\快乐的青呀\Desktop\c语言\s1e2\hello world.c unknown escape sequence: '\040'
98 2 C:\Users\快乐的青呀\Desktop\c语言\s1e2\hello world.c stray '\327' in program
98 2 C:\Users\快乐的青呀\Desktop\c语言\s1e2\hello world.c stray '\334' in program
98 2 C:\Users\快乐的青呀\Desktop\c语言\s1e2\hello world.c stray '\274' in program
98 2 C:\Users\快乐的青呀\Desktop\c语言\s1e2\hello world.c stray '\306' in program
98 48 C:\Users\快乐的青呀\Desktop\c语言\s1e2\hello world.c expected expression before ')' token
99 2 C:\Users\快乐的青呀\Desktop\c语言\s1e2\hello world.c stray '\317' in program
99 2 C:\Users\快乐的青呀\Desktop\c语言\s1e2\hello world.c stray '\265' in program
99 2 C:\Users\快乐的青呀\Desktop\c语言\s1e2\hello world.c stray '\315' in program
99 2 C:\Users\快乐的青呀\Desktop\c语言\s1e2\hello world.c stray '\263' in program
101 2 C:\Users\快乐的青呀\Desktop\c语言\s1e2\hello world.c stray '\267' in program
101 2 C:\Users\快乐的青呀\Desktop\c语言\s1e2\hello world.c stray '\265' in program
101 2 C:\Users\快乐的青呀\Desktop\c语言\s1e2\hello world.c stray '\273' in program
101 2 C:\Users\快乐的青呀\Desktop\c语言\s1e2\hello world.c stray '\330' in program
C:\Users\快乐的青呀\Desktop\c语言\s1e2\hello world.c At top level:
103 2 C:\Users\快乐的青呀\Desktop\c语言\s1e2\hello world.c expected identifier or '(' before '}' token
104 2 C:\Users\快乐的青呀\Desktop\c语言\s1e2\hello world.c expected identifier or '(' before '}' token
105 2 C:\Users\快乐的青呀\Desktop\c语言\s1e2\hello world.c expected identifier or '(' before '}' token
#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");
}
xiaosi4081 发表于 2020-6-2 07:15
现在还是不可以直接输入中文吗。要输入英文的对吧
页:
[1]