请问一下 这段代码在dv上能运行 为什么在vc上运行不了啊
请问一下 这段代码在dv上能运行 为什么在vc上运行不了啊?纯新手一枚各位大佬勿喷{:1_906:}
#include<stdio.h>
#include<string.h>
struct Man
{
char Name;
char Depart;
char Tel;
char Email;
};
void getch()
{
char stop;
printf("\n确认?(按任意键和回车返回!)\n");
getchar();
scanf("%c",&stop);
return;
}
int Scan(Man*pMan)
{
printf("\t\t******正在读取信息,请稍后!*****\n");
int i;
FILE*fp=fopen("sjtxl.txt","r");
if(fp==NULL)
{
printf("\t\t*****文件sjtxl.txt打开失败!*****\n");
return 0;
}
for(i=0;feof(fp);i++,pMan++)
fscanf(fp,"%s%s%s%s",pMan->Name,pMan->Depart,pMan->Tel,pMan->Email);
fclose(fp);
printf("\t\t*****文件读取成功!*****\n");
return(i-1);
}
int Save(Man*pMan,int Size)
{
int i;
FILE*out;
out=fopen("sjtxl.txt","w");
if(out==NULL)
{
printf("\t\t*****文件sjtxl.txt打开失败!*****\n");
printf("\t\t********************************\n");
return 0;
}
for(i=0;i<Size;i++,pMan++)
{
fprintf(out,"%s\t%s\t%s\t%s\n",pMan->Name,pMan->Depart,pMan->Tel,pMan->Email);
}
fclose(out);
return 1;
}
int Insert(Man*pMan,int Size)
{
int i,n;
printf("\t\t******请输入要插入数据个数!******\n");
printf("\t\t*********************************\n");
scanf("%d",&n);
for(i=0;i<n;i++)
{
printf("将要录入第%d条记录(共有%d条)\n",i+1,n);
printf("请输入姓名:\n");
scanf("%s",&pMan.Name);
printf("请输入就读学校:\n");
scanf("%s",&pMan.Depart);
printf("请输入电话:\n");
scanf("%s",&pMan.Tel);
printf("请输入Email地址:\n");
scanf("%s",&pMan.Email);
}
if(Save(pMan,Size+n))
{
printf("\t\t******数据录入成功!*****\n");
}
else
{
printf("\t\t******数据插入失败!******\n");
}
return Size+n;
}
void Modify(Man*pMan,int Size)
{
void Display();
int i=0;
char name;
char depart;
char tel;
char email;
printf("\t\t*****请输入要修改的姓名:*****\n");
printf("\t\t*****************************\n");
scanf("%s",name);
while(i<Size&&strcmp(pMan->Name,name))
{
pMan++;
i++;
}
if(!strcmp(pMan->Name,name))
{
printf("请输入修改后的姓名:\n");
scanf("%s",name);
strcpy(pMan->Name,name);
printf("请输入修改后的就读学校:\n");
scanf("%s",depart);
strcpy(pMan->Depart,depart);
printf("请输入修改后的电话:\n");
scanf("%s",tel);
strcpy(pMan->Tel,tel);
printf("请输入修改后的Email:\n");
scanf("%s",email);
strcpy(pMan->Email,email);
if(Save(pMan,Size))
{
printf("\t\t*****信息修改成功!*****\n");
printf("\t\t***********************\n");
}
else
{
printf("\t\t*****信息修改失败!*****\n");
printf("\t\t***********************\n");
}
}
else
{
printf("\t\t*****没有找到相关信息!*****\n");
printf("\t\t***************************\n");
}
}
void Delete(Man*pMan,int Size)
{
char name,control;
int i=0;
printf("\t\t*****请输入要删除信息姓名!*****\n");
printf("\t\t*******************************\n");
scanf("%s",name);
while(i<Size&&strcmp(pMan->Name,name))
{
pMan++;
i++;
}
if(!strcmp(pMan->Name,name))
{
printf("你要删除的信息为:\n");
printf("%s\t%s\t%s\t%s\n",pMan->Name,pMan->Depart,pMan->Tel,pMan->Email);
printf("是否确认删除?(Y\N)\n");
scanf("%s",&control);
switch(control)
{
case 'Y':
pMan->Name='\0';
pMan->Depart='\0';
pMan->Tel='\0';
pMan->Email='\0';
if(Save(pMan,Size))
{
printf("\t\t*****信息删除成功!*****\n");
printf("\t\t***********************\n");break;
}
else
{
printf("\t\t*****信息删除失败!*****\n");
printf("\t\t***********************\n");break;
}
case 'N':printf("信息未删除!\n");break;
default:printf("输入错误!\n");break;
}
}
else
{
printf("\t\t******没有找到相关信息!*****\n");
printf("\t\t****************************\n");
}
}
void Display(Man*pMan,int Size)
{
int i;
printf("\t姓名\t 就读学校\t 电话号码\t Email地址\n");
printf("\t\t*************************************************\n");
for(i=0;i<=Size;i++,pMan++)
{
printf("\t%s\t\t%S\t%s\t%s\n",pMan->Name,pMan->Depart,pMan->Tel,pMan->Email);
printf("\t--------------------------------------------------------------\n");
}
}
void S_asname(Man*pMan,int Size)
{
int i=0;
char name;
printf("\t\t*****请输入要查询信息的姓名:*****\n");
printf("\t\t*********************************\n");
scanf("%s",name);
while(i<Size&&strcmp(pMan->Name,name))
{
pMan++;
i++;
}
if(!strcmp(pMan->Name,name))
{
printf("\t\t*****查到的信息为:*****\n");
printf("\t*************************\n");
printf("\t 姓名 \t 就读学校 \t 电话号码 \t Email\n");
printf("\t**************************************\n");
("\t%s\t\t%s\t%s\t%s\n",pMan->Name,pMan->Depart,pMan->Tel,pMan->Email);
printf("\t********************************************************\n");
}
else
{
printf("\t\t*****没有找到相关数据*****\n");
printf("\t\t**************************\n");
}
}
void S_astel(Man*pMan,int Size)
{
int i=0;
char tel;
printf("\t\t***** 请输入要查询信息的电话:*****\n");
printf("\t\t**********************************\n");
scanf("%s",tel);
while(i<Size&&strcmp(pMan->Tel,tel))
{
pMan++;
i++;
}
if(!strcmp(pMan->Tel,tel))
{
printf("\t\t*****查到的信息为:*****\n");
printf("\t*************************\n");
printf("\t 姓名 \t 就读学校 \t 电话号码 \t Email\n");
printf("\t**************************************\n");
printf("\t%s\t\t%s\t%s\t%s\n",pMan->Name,pMan->Depart,pMan->Tel,pMan->Email);
printf("\t**************************************************************\n");
}
else
{
printf("\t\t*****没有找到相关数据*****\n");
printf("\t\t**************************\n");
}
}
int main()
{
Man man,*pMan=man;
char control;
int size;
printf("\t\t**********************************************\n");
printf("\t\t********** 欢迎使用通讯录管理系统 ! ***********\n");
printf("\t\t*--------------------------------------------*\n");
printf("\t\t* 请按回车键继续 ! *\n");
printf("\t\t**********************************************\n");
scanf("%c",&control);
if(control)
{
size=Scan(pMan);
printf("\t\t\t 请输入相应操作数操作 \n");
for(;;)
{
printf("\t\t**********************************************\n");
printf("\t\t* 1-- 插入信息 *\n");
printf("\t\t* 2--按姓名查找 *\n");
printf("\t\t* 3-- 按电话查找 *\n");
printf("\t\t* 4-- 删除信息 *\n");
printf("\t\t* 5-- 显示信息 *\n");
printf("\t\t* 6-- 修改信息 *\n");
printf("\t\t* 0-- 退出系统 *\n");
printf("\t\t**********************************************\n");
scanf("%s",&control);
switch(control)
{
case '1': size=Insert(pMan,size);break;
case '2': S_asname(pMan,size);break;
case '3': S_astel(pMan,size);break;
case '4': Delete(pMan,size);break;
case '5': Display(pMan,size);break;
case '6': Modify(pMan,size);break;
case '0': printf("************** 谢谢使用 !再见 !**************\n");
return 0;
default: printf("********** 输 入 数 字 有 误 , 请 重 新 输 入**********\n");break;
}
}
}
return 0;
} 看编译ERROR信息,你这谁知道什么问题 JuncoJet 发表于 2021-5-17 21:53
看编译ERROR信息,你这谁知道什么问题
1>------ Build started: Project: meidu, Configuration: Debug Win32 ------
1>3344.c
1>e:\vc2010\meidu\meidu\3344.c(17): warning C4996: 'scanf': This function or variable may be unsafe. Consider using scanf_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.
1> c:\program files (x86)\microsoft visual studio 10.0\vc\include\stdio.h(304) : see declaration of 'scanf'
1>e:\vc2010\meidu\meidu\3344.c(21): error C2143: syntax error : missing ')' before '*'
1>e:\vc2010\meidu\meidu\3344.c(21): error C2143: syntax error : missing '{' before '*'
1>e:\vc2010\meidu\meidu\3344.c(21): error C2059: syntax error : ')'
1>e:\vc2010\meidu\meidu\3344.c(22): error C2054: expected '(' to follow 'pMan'
1>e:\vc2010\meidu\meidu\3344.c(38): error C2143: syntax error : missing ')' before '*'
1>e:\vc2010\meidu\meidu\3344.c(38): error C2143: syntax error : missing '{' before '*'
1>e:\vc2010\meidu\meidu\3344.c(38): error C2059: syntax error : 'type'
1>e:\vc2010\meidu\meidu\3344.c(38): error C2059: syntax error : ')'
1>e:\vc2010\meidu\meidu\3344.c(57): error C2143: syntax error : missing ')' before '*'
1>e:\vc2010\meidu\meidu\3344.c(57): error C2143: syntax error : missing '{' before '*'
1>e:\vc2010\meidu\meidu\3344.c(57): error C2059: syntax error : 'type'
1>e:\vc2010\meidu\meidu\3344.c(57): error C2059: syntax error : ')'
1>e:\vc2010\meidu\meidu\3344.c(86): error C2143: syntax error : missing ')' before '*'
1>e:\vc2010\meidu\meidu\3344.c(86): error C2143: syntax error : missing '{' before '*'
1>e:\vc2010\meidu\meidu\3344.c(86): error C2059: syntax error : 'type'
1>e:\vc2010\meidu\meidu\3344.c(86): error C2059: syntax error : ')'
1>e:\vc2010\meidu\meidu\3344.c(134): error C2143: syntax error : missing ')' before '*'
1>e:\vc2010\meidu\meidu\3344.c(134): error C2143: syntax error : missing '{' before '*'
1>e:\vc2010\meidu\meidu\3344.c(134): error C2059: syntax error : 'type'
1>e:\vc2010\meidu\meidu\3344.c(134): error C2059: syntax error : ')'
1>e:\vc2010\meidu\meidu\3344.c(150): warning C4129: 'N' : unrecognized character escape sequence
1>e:\vc2010\meidu\meidu\3344.c(180): error C2143: syntax error : missing ')' before '*'
1>e:\vc2010\meidu\meidu\3344.c(180): error C2143: syntax error : missing '{' before '*'
1>e:\vc2010\meidu\meidu\3344.c(180): error C2059: syntax error : 'type'
1>e:\vc2010\meidu\meidu\3344.c(180): error C2059: syntax error : ')'
1>e:\vc2010\meidu\meidu\3344.c(192): error C2143: syntax error : missing ')' before '*'
1>e:\vc2010\meidu\meidu\3344.c(192): error C2143: syntax error : missing '{' before '*'
1>e:\vc2010\meidu\meidu\3344.c(192): error C2059: syntax error : 'type'
1>e:\vc2010\meidu\meidu\3344.c(192): error C2059: syntax error : ')'
1>e:\vc2010\meidu\meidu\3344.c(220): error C2143: syntax error : missing ')' before '*'
1>e:\vc2010\meidu\meidu\3344.c(220): error C2143: syntax error : missing '{' before '*'
1>e:\vc2010\meidu\meidu\3344.c(220): error C2059: syntax error : 'type'
1>e:\vc2010\meidu\meidu\3344.c(220): error C2059: syntax error : ')'
1>e:\vc2010\meidu\meidu\3344.c(250): error C2065: 'Man' : undeclared identifier
1>e:\vc2010\meidu\meidu\3344.c(250): error C2146: syntax error : missing ';' before identifier 'man'
1>e:\vc2010\meidu\meidu\3344.c(250): error C2065: 'man' : undeclared identifier
1>e:\vc2010\meidu\meidu\3344.c(250): error C2109: subscript requires array or pointer type
1>e:\vc2010\meidu\meidu\3344.c(250): error C2065: 'man' : undeclared identifier
1>e:\vc2010\meidu\meidu\3344.c(251): error C2143: syntax error : missing ';' before 'type'
1>e:\vc2010\meidu\meidu\3344.c(252): error C2143: syntax error : missing ';' before 'type'
1>e:\vc2010\meidu\meidu\3344.c(258): error C2065: 'control' : undeclared identifier
1>e:\vc2010\meidu\meidu\3344.c(259): error C2065: 'control' : undeclared identifier
1>e:\vc2010\meidu\meidu\3344.c(261): error C2065: 'size' : undeclared identifier
1>e:\vc2010\meidu\meidu\3344.c(261): warning C4013: 'Scan' undefined; assuming extern returning int
1>e:\vc2010\meidu\meidu\3344.c(274): error C2065: 'control' : undeclared identifier
1>e:\vc2010\meidu\meidu\3344.c(275): error C2065: 'control' : undeclared identifier
1>e:\vc2010\meidu\meidu\3344.c(277): error C2065: 'size' : undeclared identifier
1>e:\vc2010\meidu\meidu\3344.c(277): warning C4013: 'Insert' undefined; assuming extern returning int
1>e:\vc2010\meidu\meidu\3344.c(277): error C2065: 'size' : undeclared identifier
1>e:\vc2010\meidu\meidu\3344.c(278): warning C4013: 'S_asname' undefined; assuming extern returning int
1>e:\vc2010\meidu\meidu\3344.c(278): error C2065: 'size' : undeclared identifier
1>e:\vc2010\meidu\meidu\3344.c(279): warning C4013: 'S_astel' undefined; assuming extern returning int
1>e:\vc2010\meidu\meidu\3344.c(279): error C2065: 'size' : undeclared identifier
1>e:\vc2010\meidu\meidu\3344.c(280): warning C4013: 'Delete' undefined; assuming extern returning int
1>e:\vc2010\meidu\meidu\3344.c(280): error C2065: 'size' : undeclared identifier
1>e:\vc2010\meidu\meidu\3344.c(281): warning C4013: 'Display' undefined; assuming extern returning int
1>e:\vc2010\meidu\meidu\3344.c(281): error C2065: 'size' : undeclared identifier
1>e:\vc2010\meidu\meidu\3344.c(282): warning C4013: 'Modify' undefined; assuming extern returning int
1>e:\vc2010\meidu\meidu\3344.c(282): error C2065: 'size' : undeclared identifier
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
是这个吗?? 17行已经写了,scanf不安全,用scanf_s替代 dv是啥?
typedef stuct{
}
Man;
? 这个是一个安全检查,强制你调用安全的API,不过这个选项可以关掉 需要 typedef 写struct
不然 int Scan(Man*pMan) 编译不过,另外需要空格 int Scan(Man *pMan)
不知道是不是你贴上来的问题
页:
[1]