为啥第一个程序在VS2019上无法运行?
有大佬知道吗 感谢 就是测试当前代码量的程序问问题建议将问题情况描述清晰些
代码问题发代码,出现报错也顺便将报错信息一同发出
截图发一下呀无字天书、、
第一步:仔细的检查代码是否错误(符号都是英文状态输入)
第二步:复制代码及错误,重新编辑到所在帖子上,代码按照规范粘贴。
第三步:等待回答(中间可以问别人和百度)
最后,我说的很详细了吧 本帖最后由 Abberdeer 于 2021-6-1 23:54 编辑
咋上传不了图片啊{:10_266:}
#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;
} 在运行中提示我将fopen替换为fopen_s
strcpy替换为strcpy_s
strcat_s……
诸如此类 版本问题,最开始我也一样,下面有一个官方的解决办法,点一下问题序号看一下就懂了 关闭安全检查
页:
[1]