c语言程序在devc++能正常运行但在vc++上运行到一半就结束了 - 爱问答

(爱问答)

c语言程序在devc++能正常运行但在vc++上运行到一半就结束了

#include"stdio.h"

#include"stdlib.h"

#include"string.h"

 

typedef struct phonebook

{

char name[5];

    char num[12];

struct phonebook *next;

}PHB,*phb;

 

phb Create_PHB();

void Output(phb phonenum);

phb Search(phb pnum,char *search);

phb Insert(phb pnum,PHB t,int pos);

int Length(phb pnum);

phb find_pos(phb pnum,int pos);

phb Delete(phb pnum,char *dn);

phb Sort(phb pnum,int p);

phb Modify(phb pnum);

 

int main()

{

phb pnum;

PHB t;

char search[20],dn[20];

int pos,flag;

pnum=Create_PHB();

do

{

printf("You want to 1.Search contacts 2.Delete contacts 3.Check the phonebook 4.Sort the contacts 5.Modify information of contacts 6.Insert a contact Others.Exit the programme ");

scanf("%d",&flag);

getchar();

if(flag == 1)

{

printf("Input name or phonenumber of the contact you want to look for ");

gets(search);

phb result=Search(pnum,search);

if(!result)

printf("Not found! ");

else

printf("%s %s ",result->name,result->num);

}

else if(flag == 2)

{

printf("Input name or phonenumber of the contact you want to delete ");

gets(dn);

pnum=Delete(pnum,dn);

Output(pnum);

}

else if(flag == 3)

{

printf("PHONEBOOK ");

Output(pnum);

}

else if(flag == 4)

{

int p;

printf("Input 1 to sort by name and 0 by phonenumber ");

scanf("%d",&p);

if(p<0||p>1)

{

printf("Failed to sort! ");

continue;

}

pnum=Sort(pnum,p);

Output(pnum);

}

else if(flag == 5)

{

pnum=Modify(pnum);

Output(pnum);

}

else if(flag == 6)

{

int n=Length(pnum);

printf("Input the contact's position you want to insert in ");

scanf("%d",&pos);

if(pos<0||pos>n+1)

{

printf("Illigal position! ");

continue;

}

printf("Input name and phonenumber of the contact ");

scanf("%s%s",t.name,t.num);

pnum=Insert(pnum,t,pos);

Output(pnum);

}

}while(flag>=1&&flag<=6);

return 0;

}

 

phb Create_PHB()//创建不带头结点链表 

{

phb head=NULL,p,q=NULL;

int n,i;

printf("You want to 1.Create a contact 2.Done ");

scanf("%d",&n);

getchar();

while(n == 1)

{

p=(phb)malloc(sizeof(PHB));

printf("Input name ");

gets(p->name);

printf("Input phonenumber ");

    gets(p->num);

if(!head) head=p;

else q->next=p;

q=p;

printf("You want to 1.Continue creating 2.Done ");

scanf("%d",&n);

getchar();

}

//q=NULL;

return head;

}

 

phb Search(phb pnum,char *search)

{

while(pnum&&strcmp(search,pnum->name)&&strcmp(search,pnum->num))

pnum=pnum->next;

return pnum;

}

 

int Length(phb pnum)//计算链表长度 

{

int n=0;

while(pnum)

{

n++;

pnum=pnum->next;

}

return n;

}

 

phb find_pos(phb pnum,int pos)//通过位置找结点 

{

int i;

for(i=1;pnum&&i<pos;i++)

pnum=pnum->next;

return pnum; 

}

 

phb Insert(phb pnum,PHB t,int pos)//链表的插入 

{

int i;

phb p,q=(phb)malloc(sizeof(PHB));

strcpy(q->name,t.name);

strcpy(q->num,t.num);

if(pos == 1)

q->next=pnum,pnum=q;

else

{

p=find_pos(pnum,pos-1);

q->next=p->next;

p->next=q;

}

return pnum;

}

 

phb Delete(phb pnum,char *dn)

{

phb t,p;

t=pnum;

if(!strcmp(dn,t->name)||!strcmp(dn,t->num))//要删除的为第一个结点 

{

pnum=pnum->next;

free(t);

}

else

{

p=pnum->next;

while(p&&strcmp(dn,p->name)&&strcmp(dn,p->num))//找到目标结点 

{

t=p;

p=p->next;//t始终在p前一个结点 

}

if(!p) printf("Cannot find the contact! ");

else

{

t->next=p->next;

free(p);//删除结点 

}

}

return pnum;

}

 

phb Sort(phb pnum,int p)

{

int n=Length(pnum),i,j;

phb a,b,t=(phb)malloc(sizeof(PHB));

for(i=1;i<n;i++)

for(a=pnum,b=pnum->next,j=0;j<n-i;j++,a=a->next,b=b->next)

{

if(p)

{

if(strcmp(a->name,b->name)>0)//按姓名排序 

    {

    strcpy(t->name,a->name),strcpy(t->num,a->num);

    strcpy(a->name,b->name),strcpy(a->num,b->num);

    strcpy(b->name,t->name),strcpy(b->num,t->num);

    }

}

else

{

if(strcmp(a->num,b->num)>0)//按电话号码排序 

{

strcpy(t->name,a->name),strcpy(t->num,a->num);

    strcpy(a->name,b->name),strcpy(a->num,b->num);

    strcpy(b->name,t->name),strcpy(b->num,t->num);

}

}

}

return pnum;

}

 

phb Modify(phb pnum)

{

phb t,a=(phb)malloc(sizeof(PHB));

char p[20];

t=pnum;

printf("Input name or phonenumber of the contact you want to modify ");

gets(p);

while(t&&strcmp(p,t->name)&&strcmp(p,t->num))

t=t->next;

if(!t)//未找到 

{

printf("Cannot find the contact! ");

return pnum;

}

printf("Input new name ");

gets(t->name);

printf("Input new phonenumber ");//输入修改数据 

gets(t->num);

return pnum;

}

 

void Output(phb pnum)

{

while(pnum)

{

printf("%s %s ",pnum->name,pnum->num);

pnum=pnum->next;

}

}

调试时出现这个c语言程序在devc++能正常运行但在vc++上运行到一半就结束了

求解,谢谢

1.可能是程序出现问题,建议重启或重启主电源。推荐此方法

2.也有可能是您打开的程序过多,请关闭不需要程序,只保留主程序,再试试。推荐此方法

3.可能是您的电脑热量过大,得到错误信息,程序出现矛盾。建议关机以后15分钟再试。

4.可能语言等程序内部出现问题,请找营业厅帮助。

5.如还有问题,请下载【360安全卫士】点击并进行全面诊断,发现中途中断或卡顿况很有可能是您的线路板已烧坏,请找专家更换。非广告

6.如上面5回答还没有解决,可能是您的主机已完全损坏【百分之10的可能性】。

相关标签:vcc语言

下一篇:2500元组装一台能玩方舟生存进化的电脑

上一篇:怎么制作flash8椭圆方框?

热门标签:
excel 网盘 破解 word dll
最新更新:
微软重新评估新的Outlook的使用时机 联想推出搭载联发科Helio G80芯片组的Tab M9平板 英特尔创新大赛时间确定! 微软Edge浏览器在稳定渠道中推出Workspaces功能 英伟达RTX4060TiGPU推出MaxSun动漫主题! 谷歌地图为用户提供了街景服务! GameSir 在T4 Kaleid中推出了一款出色的控制器! 微软开始在Windows 11 中测试其画图应用程序的新深色模式! LG电子推出全球首款无线OLED电视 英伟达人工智能芯片崭露头角! Steam Deck可以玩什么游戏-Steam Deck价格限时优惠 雷蛇推出CobraPro鼠标 Kindle电子阅读器可以访问谷歌商店吗 Windows10如何加入组策略 window10图片查看器怎么没有了?