辞旧690 2022-01-04 16:44 采纳率: 75%
浏览 14
已结题

为啥无法进行修改功能,是哪出错了

#include <stdio.h>
#include <stdlib.h>//用system函数为清除屏幕命令。
#include <string.h>
#include <math.h>
struct _PACKAGE
{
char no[10];//快递单号
char name[20];//收货人
char tel[20];//收货人号码
char add[40];//收货人地址
char cate[10];//运单种类
char com[10];//承运公司
char time[20];//到达时间
struct _PACKAGE next;
};
FILE fp;
struct _PACKAGE
p1,
p2,* head;
void creat()
{
FILE *fp;
int a;
struct _PACKAGE *s,*head,*tail;
head=NULL;
tail=NULL;
system("cls");
if((fp=fopen("E:\程序\快递包裹管理系统作业\record.txt","a"))==NULL)
{
printf("打开文件失败");
}

do
{
s=(struct _PACKAGE  *)malloc(sizeof(struct _PACKAGE));//开辟新链表
//fread(s,sizeof(struct _PACKAGE),1,fp);
printf("快递单号:");
scanf("%s",&s->no);
printf("\n收货人:");
scanf("%s",s->name);
printf("\n收货人号码:");
scanf("%s",s->tel);
printf("\n收货人地址:");
scanf("%s",s->add);
printf("\n运单种类:");
scanf("%s",s->cate);
printf("\n乘运公司:");
scanf("%s",s->com);
printf("\n到达时间:");
scanf("%s",s->time);
if(head==NULL) head=s;
else tail->next=s;
tail=s;
fwrite(s,sizeof(struct _PACKAGE ),1,fp);
//fprintf(fp,"%d\t%s\t%s\t\t%s\t\t%s\t%s\t%s\n",s->no,s->name,s->tel,s->add,s->cate,s->com,s->time);
printf("继续请输入任意非零数字||退出请输入0\n");
scanf("%d",&a);
system("cls");
}while(a!=0);
fclose(fp);

}
int main()
{
int i;
do
{
system("cls");
printf("\t\t 欢迎使用快递包裹管理系统***\n");
printf("\t\t * *\n");
printf("\t\t * 1:录入数据 *\n");
printf("\t\t * *\n");
printf("\t\t * 2:修改数据 *\n");
printf("\t\t * *\n");
printf("\t\t * 0:退出 *\n");
printf("\t\t * *\n");
printf("\t\t **********************************************\n");
printf("\t 请选择所要进行的操作(0-5):");
scanf("%d",&i);
printf("\n");
switch(i)
{
case 1:creat();break;
case 2:EditRecord();break;
default:printf("选择有误.\n");break;
}
}while(i);
return 0;
}
int CreatLinkTa()
{
char n=0;
system("cls");
if((fp=fopen("E:\程序\快递包裹管理系统作业\record.txt","rb"))==NULL)
{
printf("打开文件错误,按任意键退出......");
system("pause");
return;
}
do
{
p1=( struct _PACKAGE )malloc(sizeof(struct _PACKAGE ));
//p2=p1;
if((fread(p1,sizeof(struct _PACKAGE),1,fp)!=1)&&(feof(fp)))
{
printf("文件读入结束!按任意键退出......\n");
system("pause");
break;
}
n++;
if(n==1)
head=p1;
else
p2->next=p1;
p2=p1;
}while(!feof(fp));
p1->next=NULL;
p1=head;
fclose(fp);
printf("链表产生完毕\n");
system("pause");
p1=p2=head;
printf("链表显示完毕,按任意键继续……\n");
return;
}
/修改记录
/
void creatt(struct _PACKAGE
s)
{
printf("快递单号:");
scanf("%s",&s->no);
printf("\n收货人:");
scanf("%s",s->name);
printf("\n收货人号码:");
scanf("%s",s->tel);
printf("\n收货人地址:");
scanf("%s",s->add);
printf("\n运单种类:");
scanf("%s",s->cate);
printf("\n乘运公司:");
scanf("%s",s->com);
printf("\n到达时间:");
scanf("%s",s->time);
}
void XIUGAI()
{
char num[10];
int n=0;
struct _PACKAGE *q;
p2=p1;
printf("\n请输入快递单号:");
scanf("%s",num);
while(p1!=NULL)
{ n++;
if(stricmp(p1->no,num)==0)
{
printf("快递单号\t收货人\t收货人号码\t收货人地址\t运单种类\t承运公司\t到达时间\n");
printf("%s\t%s\t%d\t%s\t%s\t%s\t%s\t%s\n",p1->no,p1->name,p1->tel,p1->add,p1->cate,p1->com,p1->time);
printf("按任意键进入修改模式......\n");
system("pause");
q=( struct _PACKAGE *)malloc(sizeof(struct _PACKAGE ));
creatt(q);//
q->next=NULL;
if(n==1){head=p2=q;q->next=p1->next;p1=q;}
else {q->next=p1->next;p2->next=q;p1=q;}
}
p2=p1;
p1=p1->next;
} //while end
printf("按任意键进入修改结束......\n");
system("pause");
p1=p2=head;
if((fp=fopen("E:\程序\快递包裹管理系统作业\record.txt","wb"))==NULL)
{
printf("打开文件错误,按任意键退出....\n");
system("pause");
return;
}

while(p1!=NULL)
{
    if(fwrite(p1,sizeof(struct  _PACKAGE),1,fp)!=1)
    {
        printf("写入错误!按任意键退出......\n");
        system("pause");

;
break;
}
p1=p1->next;
}
printf("修改结束!按任意键退出......\n");
system("pause");
fclose(fp);
}

void EdReNam()
{
char str[10];
int n=0;
struct _PACKAGE *q;
p2=p1;
printf("\n请输入姓名:");
scanf("%s",str);
while(p1!=NULL)
{ n++;
if(strcmp(p1->name,str)==0)
{
printf("快递单号\t收货人\t收货人号码\t收货人地址\t运单种类\t承运公司\t到达时间\n");
printf("%s\t%s\t%d\t%s\t%s\t%s\t%s\t%s\n",p1->no,p1->name,p1->tel,p1->add,p1->cate,p1->com,p1->time);
printf("按任意键进入修改模式......\n");
system("pause");
q=( struct _PACKAGE *)malloc(sizeof(struct _PACKAGE ));
creatt(q); //
q->next=NULL;
if(n==1){head=p2=q;q->next=p1->next;p1=q;}
else {q->next=p1->next;p2->next=q;p1=q;}
}
p2=p1;
p1=p1->next;
} //while end
printf("按任意键开始修改......\n");
system("pause");
p1=p2=head;
if((fp=fopen("E:\程序\快递包裹管理系统作业\record.txt","wb"))==NULL)
{
printf("打开文件错误,按任意键退出....\n");
system("pause");
return;
}

while(p1!=NULL)
{
    if(fwrite(p1,sizeof(struct   _PACKAGE),1,fp)!=1)
    {
        printf("写入错误!按任意键退出......\n");
       system("pause");
        break;
    }
    p1=p1->next;
}
printf("修改结束!按任意键退出......\n");
 system("pause");
fclose(fp);

}
int EditRecord()
{
int i;
CreatLinkTa(); //生成链表,head、p1指向表头
while(1)
{
system("cls");
printf("\t\t欢 迎 使 用 本 修 改 模 块\n");
printf("\t\t* \n");
printf("\t\t
1:按职运单号修改 \n");
printf("\t\t
\n");
printf("\t\t
2:按姓名修改 \n");
printf("\t\t
\n");
printf("\t\t
0:退出 \n");
printf("\t\t
*\n");
printf("\t\t
****************
**********************************\n");
printf("\t\t 请选择所要进行的操作(0-2):");
scanf("%d",&i);
printf("\n");
switch(i)
{
case 0: return;
case 1:{XIUGAI();break;}
case 2:{ EdReNam();break;}
default:break;
}

}
return;
}

  • 写回答

1条回答 默认 最新

  • 於黾 2022-01-04 17:00
    关注

    scanf("%s",num);
    改为scanf("%s",&num);
    每天都有2个人犯这样的错误

    评论

报告相同问题?

问题事件

  • 已结题 (查看结题原因) 5月30日
  • 创建了问题 1月4日

悬赏问题

  • ¥15 惠普360g9的最新bios
  • ¥15 配置hadoop时start-all.sh老是启动失败
  • ¥30 这个功能用什么软件发合适?
  • ¥60 微信小程序,取消订单,偶尔订单没有改变状态
  • ¥15 用pytorch实现PPO算法
  • ¥15 关于调制信号的星座图?
  • ¥30 前端传参时,后端接收不到参数
  • ¥15 这是有什么问题吗,我检查许可证了但是显示有呢
  • ¥15 机器学习预测遇到的目标函数问题
  • ¥15 Fluent,液体进入旋转区域体积分数不连续