strcpy(thePath, path); 为什么这一行一直显示有问题
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
#include<io.h>
#include<direct.h>
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#define MAX 256
long total;
int countLines(const char *filrname);
void findAllCodes(const char *path);
void findALLsFiles(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)
{
print(stderr,"The path %s is wrong!\n",path);
return;
}
do
{
if(!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("16:19目前你总共写了%1d 行代码\n\n",total);
system("pause");
return 0;
}
#include<io.h>
#include<direct.h>
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#define MAX 256
long total;
int countLines(const char *filrname);
void findAllCodes(const char *path);
void findALLsFiles(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)
{
print(stderr,"The path %s is wrong!\n",path);
return;
}
do
{
if(!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("16:19目前你总共写了%1d 行代码\n\n",total);
system("pause");
return 0;
}
#include<io.h>
#include<direct.h>
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#define MAX 256
long total;
int countLines(const char *filrname);
void findAllCodes(const char *path);
void findALLsFiles(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)
{
print(stderr,"The path %s is wrong!\n",path);
return;
}
do
{
if(!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("16:19目前你总共写了%1d 行代码\n\n",total);
system("pause");
return 0;
}
#include<io.h>
#include<direct.h>
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#define MAX 256
long total;
int countLines(const char *filrname);
void findAllCodes(const char *path);
void findALLsFiles(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)
{
print(stderr,"The path %s is wrong!\n",path);
return;
}
do
{
if(!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("16:19目前你总共写了%1d 行代码\n\n",total);
system("pause");
return 0;
}
#include<io.h>
#include<direct.h>
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#define MAX 256
long total;
int countLines(const char *filrname);
void findAllCodes(const char *path);
void findALLsFiles(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)
{
print(stderr,"The path %s is wrong!\n",path);
return;
}
do
{
if(!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("16:19目前你总共写了%1d 行代码\n\n",total);
system("pause");
return 0;
}
编译单个文件...
--------
- 文件名: C:\Users\Administrator.WIN-1HG23H1KLBU\Desktop\c语言\第二节课\超长代码的一部分.cpp
- 编译器名: TDM-GCC 4.9.2 64-bit Release
处理 C++ 源文件...
--------
- C++ 编译器: C:\Program Files (x86)\Dev-Cpp\MinGW64\bin\g++.exe
- 命令: g++.exe "C:\Users\Administrator.WIN-1HG23H1KLBU\Desktop\c语言\第二节课\超长代码的一部分.cpp" -o "C:\Users\Administrator.WIN-1HG23H1KLBU\Desktop\c语言\第二节课\超长代码的一部分.exe"-I"C:\Program Files (x86)\Dev-Cpp\MinGW64\include" -I"C:\Program Files (x86)\Dev-Cpp\MinGW64\x86_64-w64-mingw32\include" -I"C:\Program Files (x86)\Dev-Cpp\MinGW64\lib\gcc\x86_64-w64-mingw32\4.9.2\include" -I"C:\Program Files (x86)\Dev-Cpp\MinGW64\lib\gcc\x86_64-w64-mingw32\4.9.2\include\c++" -L"C:\Program Files (x86)\Dev-Cpp\MinGW64\lib" -L"C:\Program Files (x86)\Dev-Cpp\MinGW64\x86_64-w64-mingw32\lib" -static-libgcc
C:\Users\Administrator.WIN-1HG23H1KLBU\Desktop\c语言\第二节课\超长代码的一部分.cpp: In function 'void findAllCodes(const char*)':
C:\Users\Administrator.WIN-1HG23H1KLBU\Desktop\c语言\第二节课\超长代码的一部分.cpp:47:3: error: expected initializer before 'strcpy'
strcpy(thePath, path);
^
C:\Users\Administrator.WIN-1HG23H1KLBU\Desktop\c语言\第二节课\超长代码的一部分.cpp:52:12: error: 'target' was not declared in this scope
sprintf(target, "%s/%s", path, fa.name);
^
C:\Users\Administrator.WIN-1HG23H1KLBU\Desktop\c语言\第二节课\超长代码的一部分.cpp: In function 'void findAllDirs(const char*)':
C:\Users\Administrator.WIN-1HG23H1KLBU\Desktop\c语言\第二节课\超长代码的一部分.cpp:69:58: error: 'print' was not declared in this scope
print(stderr,"The path %s is wrong!\n",path);
这三处错误是什么意思?? 努力学C的我 发表于 2020-10-1 16:44
编译单个文件...
--------
- 文件名: C:%users\Administrator.WIN-1HG23H1KLBU\Desktop\c语言\第二节 ...
你这发的是什么呀? // 该程序必须在 C 编译器下运行,C++ 编译器下不能运行!
// 有些编译器对缩进也有严格的要求,所以,请不要改变每一行前的空格!
#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); // C要大写
findALLDirs(path);
printf("目前你总共写了 %ld 行代码! \n\n", total);
system("pause");
return 0;
}
#include<io.h>
#include<direct.h>
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#define MAX 256
long total;
int countLines(const char* filrname);
void findAllCodes(const char* path);
void findALLsFiles(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不是print
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);
// 小写l 不是1
printf("16:19目前你总共写了%ld行代码\n\n", total);
system("pause");
return 0;
} 45行少了分号,70行是fprintf不是print, 77行抄错了
100是ld(小写L)不是1d(不是数字1)
页:
[1]