我写的时候已经尽量的考虑在TC下编了!
麻烦给看看怎样修改以后才能在TC下编译通过!
程序如下:
/*End file by TY*/
#include <stdlib.h>
#include <stdio.h>
int menu(void);
void addrecord(void);
void browserecord(void);
void delrecord(void);
void editrecord(void);
void lookforrecord(void);
#include <string.h>
struct stinf
{
char name[20];
char id[20];
char age[3];
char sex[6];
char tel[12];
char adress[30];
stinf *p;
};
void printrecord(stinf*);
stinf* phead = NULL;
void main()
{
int select;
ag: select = menu();
switch(select)
{
case 1:addrecord();break;
case 2:delrecord();break;
case 3:lookforrecord();break;
case 4:editrecord();break;
case 5:browserecord();break;
case 6:break;
default:;
}
if(select != 6)goto ag;
}
int menu()
{
int choice = 0;
ag1: system("cls");
printf("学生信息管理 Ver1.00\n");
printf("请选择你想进行的操作:\n");
printf("1 - 增加一个纪录\n");
printf("2 - 删除一个记录\n");
printf("3 - 查找一个记录\n");
printf("4 - 修改一个纪录\n");
printf("5 - 浏览所有记录\n");
printf("6 - 退出信息管理\n");
printf("请输入你的操作选择:");
scanf("%i",&choice);
if(choice < 1 || choice > 6)
{
printf("输入有误!请重新输入!\n");
system("pause");
goto ag1;
}
system("cls");
return choice;
}
void addrecord()
{
stinf* padd;
stinf* ptemp;
ptemp = new stinf;
ptemp->p = NULL;
printf("添加新记录!\n请输入学生的姓名:");
scanf("%s",ptemp->name);
printf("请输入学号:");
scanf("%s",&(ptemp->id));
printf("请输入年龄:");
scanf("%s",&(ptemp->age));
printf("请输入性别:");
scanf("%s",ptemp->sex);
printf("请输入电话:");
scanf("%s",&(ptemp->tel));
printf("请输入住址:");
scanf("%s",ptemp->adress);
printf("\n学生信息为:");
printrecord(ptemp);
printf("纪录添加完成!\n");
padd = phead;
if(padd != NULL)
{
while(padd->p != NULL)
{
padd = padd->p;
}
padd->p = ptemp;
padd = padd->p;
}
else phead = ptemp;
system("pause");
}
void delrecord()
{
int i = 0;
int c = 1;
printf("学生信息的纪录号请通过纪录浏览的功能确定!\n");
printf("请输入要删除的记录号:");
scanf("%d",&i);
stinf* pdel;
stinf* pdtemp;
stinf* psave;
pdel = phead;
if(i != 1)
{
for(c = 0; c < i; c++)
{
if(pdel->p != NULL)
{
psave = pdel;
pdel = pdel->p;
c++;
}
else break;
}
}
if(c != i || phead == NULL)
{
printf("记录号有误!\n没有你所输入的纪录号!\n");
system("pause");
}
else
{
pdtemp = pdel;
if(pdtemp->p != NULL)pdtemp = pdtemp->p;
else
{
if(i == 1)
{
delete phead;
phead = NULL;
goto end;
}
else
{
delete pdel;
psave->p = NULL;
goto end;
}
}
if(i == 1)
{
delete phead;
phead = pdtemp;
goto end;
}
else
{
psave->p = pdtemp;
delete pdel;
}
end:printf("纪录删除!\n");
system("pause");
}/**/
}
void browserecord()
{
stinf* psee;
psee = phead;
int i = 1;
while(psee != NULL)
{
printf("\n第%d条纪录为:\n",i);
printrecord(psee);
i++;
psee = psee->p;
system("pause");
}
printf("\n已经浏览了所有的纪录或者纪录为空!\n");
system("pause");
}
void editrecord()
{
int i = 0;
int c = 1;
char ename[20];
char eid[20];
char eage[3];
char esex[6];
char etel[12];
char eadress[30];
printf("学生信息的纪录号请通过纪录浏览的功能确定!\n");
printf("请输入要修改的记录号:");
scanf("%d",&i);
stinf* pedit;
pedit = phead;
if(i != 1)
{
for(c = 0; c < i; c++)
{
if(pedit->p != NULL)
{
pedit = pedit->p;
c++;
}
else break;
}
}
if(c != i || phead == NULL)
{
printf("记录号有误!\n没有你所输入的纪录号!\n");
system("pause");
}
else
{
printf("修改方式:如果要修改某一项请直接输入新的内容即可,如果想使用原来的值请输入“#”\n");
printf("旧的纪录为:");
printrecord(pedit);
printf("\n请重新输入姓名:");
scanf("%s",ename);
if(ename == "#");
else strcpy((pedit->name),ename);
printf("请重新输入学号:");
scanf("%s",eid);
if(eid == "#");
else strcpy((pedit->id),eid);
printf("请重新输入年龄:");
scanf("%s",eage);
if(eage == "#");
else strcpy((pedit->age),eage);
printf("请重新输入性别:");
scanf("%s",esex);
if(esex == "#");
else strcpy((pedit->sex),esex);
printf("请重新输入电话:");
scanf("%s",etel);
if(etel == "#");
else strcpy((pedit->tel),etel);
printf("请重新输入住址:");
scanf("%s",eadress);
if(eadress == "#");
else strcpy((pedit->adress),eadress);
}
printf("修改完成!\n");
system("pause");
}
void lookforrecord()
{
char lname[20];
printf("请输入要查找的学生姓名:");
scanf("%s",lname);
stinf* plookfor;
plookfor = phead;
int i = 1;
while(plookfor != NULL)
{
if(strcmp(lname,plookfor->name) == 0)
{
printf("\n第%d条纪录满足你的条件:\n",i);
printrecord(plookfor);
system("pause");
}
i++;
plookfor = plookfor->p;
}
printf("\n已经查找了所有的纪录!\n");
system("pause");
}
void printrecord(stinf* p)
{
printf("\n姓名:%s",p->name);
printf("\n学号:%s",p->id);
printf("\n年龄:%s",p->age);
printf("\n性别:%s",p->sex);
printf("\n电话:%s",p->tel);
printf("\n住址:%s\n",p->adress);
}
你手头有TC编译器吗?有的话先编译一下,把出错结果告诉我们。
同意,有编译结果再说较好。
我觉得不会有问题!
你也没用TC没有的东西!
TC2不支持C++的,你要去掉一切C++的痕迹
象 sum_1(正在喝水)那样改。
可能问题不在编译的地方
在new或delete
不是很明白
帮你up
要是给分少给点就行
呵呵
开玩笑的
同意 sum_1(正在喝水) ,在结构中说明指向自身的指针时要加上关键字
"struct"
struct stinf
{
char name[20];
char id[20];
char age[3];
char sex[6];
char tel[12];
char adress[30];
stinf *p;//将这一句改为struct stinf *p;
};
stinf* phead = NULL;/*将这一句改为struct stinf *phead=NULL;
除非你这样写:
typedef struct stinf
{
char name[20];
char id[20];
char age[3];
char sex[6];
char tel[12];
char adress[30];
struct stinf *p;//将这一句改为struct stinf *p;
}STINF;
STINF *phead=NULL;
///////////
void addrecord()
{
STINF* padd;
STINF* ptemp;
ptemp =(STINF *) malloc(sizeof(struct stinf));
..........
错误的地方还有几处,如:
delete phead;/*改写为 free(phead); */
void printrecord(stinf*);/*改写为 void printrecord(struct stinf*);
或改为 void printrecord (STINF *);*/
加上 #include<malloc.h>
关键是有些内容是c++的,必须改为c标准才行!