|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
本帖最后由 益脑三通 于 2018-10-18 19:59 编辑
本人是0基础啊,勿喷,根据小鱼要求的 第一课 抄一遍 第一个程序【计算代码量的程序】
抄完了 运行报错:
1>main.c
1>c:\users\ipiqi\source\repos\c_course1\c_course1\main.c(22): error C4996: 'fopen': This function or variable may be unsafe. Consider using fopen_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.
1>f:\windows kits\10\include\10.0.17134.0\ucrt\stdio.h(208): note: 参见“fopen”的声明
1>c:\users\ipiqi\source\repos\c_course1\c_course1\main.c(46): error C4996: 'strcpy': This function or variable may be unsafe. Consider using strcpy_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.
1>f:\windows kits\10\include\10.0.17134.0\ucrt\string.h(133): note: 参见“strcpy”的声明
1>c:\users\ipiqi\source\repos\c_course1\c_course1\main.c(47): error C4996: 'strcat': This function or variable may be unsafe. Consider using strcat_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.
1>f:\windows kits\10\include\10.0.17134.0\ucrt\string.h(90): note: 参见“strcat”的声明
1>c:\users\ipiqi\source\repos\c_course1\c_course1\main.c(50): error C4996: 'sprintf': This function or variable may be unsafe. Consider using sprintf_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.
1>f:\windows kits\10\include\10.0.17134.0\ucrt\stdio.h(1774): note: 参见“sprintf”的声明
1>c:\users\ipiqi\source\repos\c_course1\c_course1\main.c(63): error C4996: 'strcpy': This function or variable may be unsafe. Consider using strcpy_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.
1>f:\windows kits\10\include\10.0.17134.0\ucrt\string.h(133): note: 参见“strcpy”的声明
1>c:\users\ipiqi\source\repos\c_course1\c_course1\main.c(64): error C4996: 'strcat': This function or variable may be unsafe. Consider using strcat_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.
1>f:\windows kits\10\include\10.0.17134.0\ucrt\string.h(90): note: 参见“strcat”的声明
1>c:\users\ipiqi\source\repos\c_course1\c_course1\main.c(76): error C4996: 'sprintf': This function or variable may be unsafe. Consider using sprintf_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.
1>f:\windows kits\10\include\10.0.17134.0\ucrt\stdio.h(1774): note: 参见“sprintf”的声明
1>已完成生成项目“C_Course1.vcxproj”的操作 - 失败。
========== 生成: 成功 0 个,失败 1 个,最新 0 个,跳过 0 个 ==========
一开始以为是自己抄错了 特意对了一遍 发现 没问题 !
然后复制了一份网页原文去VS2017上面 运行也发生了同意的报错!
求解啊 或者有没有 遇到同样问题的 同学们呢!
本人是 Windows10系统,开发环境:VS2017
我的代码如下:
#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 findAllFfiles(const char *path);
int countLines(const char *filename)
{
FILE *fp;
int count = 0;
int temp = 0;
if ((fp = fopen(filename, "r")) == NULL)
{
fprintf(stderr, "Can not open the file:%s <=> 无法打开这个文件:%s\n", filename, 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[MAX], target[MAX];
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[MAX];
strcpy(thePath, path);
if ((handle = _findfirst(strcat(thePath, "/*"), &fa)) == -1L)
{
fprintf(stderr, "The path %s is wrong! <=> 这个路径 %s 是错误的!\n", path, 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[MAX] = ".";
printf("计算中...\n");
findAllCodes(path);
findALLDirs(path);
printf("目前你总共写了 %ld 行代码!\n\n", total);
system("pause");
return 0;
}
#include<stdio.h>
#include<direct.h>
#include<io.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[MAX], target[MAX];
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[MAX];
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[MAX]=".";
printf("计算中...\n");
findAllCodes(path);
findALLDirs(path);
printf("目前你总共写了 %ld 行代码!\n\b", total);
system("pause");
return 0;
}
|
|