| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 2149 人关注过本帖
标题:C语言调试
只看楼主 加入收藏
黄瑶
Rank: 1
等 级:新手上路
帖 子:3
专家分:0
注 册:2016-6-28
结帖率:0
收藏
已结贴  问题点数:20 回复次数:11 
C语言调试
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <malloc.h>
#include <string.h>
typedef struct STRUCT/*定义结构体*/
{
int empnumber;/*员工编号*/
int productscount; /*产品数量*/
struct STRUCT *next;/*指向下一个节点的指针*/
}TS;/*结构体的别名*/


TS *CreateLink(TS *head) /*创建链表函数*/
{
char temp[100];
TS *p1;
p1=(TS*)malloc(sizeof(TS)); /*为一个链表节点分配存储空间*/
printf(" input employee number and the counts of products\n");
printf("exit: Double times 0 !\n"); /*两次输入0,表示退出*/
gets(temp);
p1->empnumber=atoi(temp); /*输入员工编号*/
gets(temp);
p1->productscount=atoi(temp);/*输入产品数量*/
p1->next=NULL; /*链表节点的尾指针赋值为NULL*/
while(p1->empnumber>0)/*当输入的员工编号不为0*/
{/*if(head==NULL)
    head=p1;第一次插入,插在表头*/
TS *InsertIntoLink(TS* head,int empnumber,int productscount);
head=InsertIntoLink(head,p1->empnumber,p1->productscount);/*调用函数,进行节点插入*/
p1=(TS*)malloc(sizeof(TS)); /*为p1节点分配存储空间*/
printf(" input employee number and the counts of products\n");
printf("exit: Double times ENTER\n");
gets(temp);
p1->empnumber=atoi(temp); /*为p1的成员变量empnumber赋值*/
gets(temp);
p1->productscount=atoi(temp); /*为p1的成员变量赋值*/
p1->next=NULL;
}
return head; /*返回首指针*/
}



TS *InsertIntoLink(TS* head,int empnumber,int productscount) /*插入函数,有序插入*/
{
TS *p1,*p2,*p3;
p1=(TS*)malloc(sizeof(TS)); /*新建一个节点*/
p1->empnumber=empnumber; /*为节点赋值*/
p1->productscount=productscount;
p2=head; /*p2指向首节点*/
if(head==NULL) /*首节点为空*/
{
head=p1;p1->next=NULL;/*新节点插入在表头*/
printf("the head is null,so,the linklist head inserted success!\n");
}
else /*首节点不为空*/
{
while(productscount<p2->productscount&&p2->next!=NULL) /*插入产品数量少于当前节点的产品数量*/
{
p3=p2;
p2=p2->next; /*指针下移,继续搜索*/
}
if(productscount>=p2->productscount)
{
if(productscount==p2->productscount)
while(productscount==p2->productscount&&empnumber>p2->empnumber&&p2->next!=NULL) /*员工编号从小到大排序,如果要插入的员工编号比当前节点大,就继续往下搜索*/
{
p3=p2;
p2=p2->next;
}
if(head==p2) /*插在表头*/
{
head=p1;
p1->next=p2;
printf("the head is NOT null,so,the linklist head inserted success!\n");
}
else /*插在表中间*/
{
p3->next=p1;
p1->next=p2;
printf("the midle of linklist inserted success!\n");
}
}
else /*插在表尾*/
{
p2->next=p1;
p1->next=NULL;
printf("the end of linklist inserted success!\n");
}
}
printf("return the head of the linklist!\n");
return(head);
}



TS *DeletFromLink(TS *head,int empnumber) /*删除函数*/
{
TS *temp,*p;
temp=head;
if(head==NULL) printf("\n LinkList is null!\n");
else
{
temp=head;
while(temp->empnumber!=empnumber&&temp->next!=NULL) /*寻找要删除的节点*/
{
p=temp;
temp=temp->next;
}
if(temp->empnumber==empnumber) /*找到删除的员工编号*/
{
if(temp==head) /*如果是表头*/
{
head=head->next;
printf("the head :delets employee Number :%d\n",temp->empnumber); /*
打印要删除节点*/
free(temp);
}
else /*如果不是表头,也不是表尾*/
{
p->next=temp->next;
printf("delets employee Number :%d\n",temp->empnumber); /*打印要删除节点*/
free(temp);
}
}
else
printf("\n Cannot find Such Employee Number\n"); /*找不到要删除的员工*/
}
return(head);
}



TS *Search(TS *head,int empnumber)
{
TS *t;
t=head;
while(empnumber!=t->empnumber&&t->next!=NULL)
{
t=t->next;
}
if(empnumber==t->empnumber)
{
printf("Find it!\n");
return(t);
}
else
{
printf("Unable to find such employee number in the Linklist!\n");
t=NULL;
return(t);
}

void print(TS *head) /*打印函数*/
{
TS *temp,*p1;
int i=1;
temp=head;/*头指针赋值给temp,temp指向链表头*/
printf("\n output the result:\n");
printf("\n order\t\tporductscount\t\tempnumber\n");
while(temp!=NULL)
{
printf("\t%d\t\t%d\t\t\t%d\n",i,temp->productscount,temp->empnumber); /*输出序号i,产品数量,员工编号*/
i++;
temp=temp->next; /*指针下移*/
}
return 0;
}



void main()
{
TS *CreateLink(TS*); /*声明创建链表的函数*/
TS *InsertIntoLink(); /*声明插入链表的函数*/
TS *DeletFromLink(); /*声明删除函数*/
TS *Search();
void print();/*声明打印链表的函数*/
TS *head;
TS *temp;
TS *t2;
char s[100];
int empnumber=0;
int productscount=0;
int n;
head=NULL;
head=CreateLink(head); /*先创建空链表*/
temp=(TS*)malloc(sizeof(TS));
t2=(TS*)malloc(sizeof(TS));
while(1) /*一个可控制的循环*/
{
LOOP: printf("\t\t**********职工工作量统计系统**********\n\n");
printf("************1 改变职工信息***********\t");
printf("************2删除职工信息***********\n\n");
printf("************3显示职工信息***********\t");
printf("\t\t**********0 退出系统***********\n\n");
printf("your choice:");
gets(s);
if(strcmp(s,"1")!=0&&strcmp(s,"2")!=0&&strcmp(s,"3")!=0)
return 0;/*如果不是1或者2选项,就退出系统*/
if(strcmp(s,"1")==0)   /*选择选项1,进行改变员工信息操作*/
{
printf("\nPlease Input you Employee Number And Products Count you are to change!\nthe employee Number :");
gets(s);
empnumber=atoi(s);   /*输入员工编号*/
printf("\nSearching for the number,Please wait.....\n");
temp=Search(head,empnumber);
printf("\nprint the nod of temp: temp.empnumber= %d",temp->empnumber);
printf("\nprint the nod of temp: temp.productscount= %d",temp->productscount);
if(temp==NULL)
goto LOOP;
else  
t2->empnumber=temp->empnumber;
t2->productscount=temp->productscount; /* memcpy(t2,temp,sizeof(TS));*/
printf("\nprint the nod of temp: temp.empnumber= %d",temp->empnumber);
printf("\nprint the nod of temp: temp.productscount= %d",temp->productscount);
printf("\nprint the nod of temp: t2.empnumber= %d",t2->empnumber);
printf("\nprint the nod of temp: t2.productscount= %d",t2->productscount);
t2->next=NULL;
printf("\nbefore Delete the temp node....\n");
print(head);
head=DeletFromLink(head,t2->empnumber);
printf("\nafter delete the temp node....\n");
print(head);
productscount+=t2->productscount;
}
while(1) /*改循环实现产品数量累加计算*/
{
printf("Would you like to input more products count? if not,please type 0\n your Input: ");
gets(s);
if(strcmp(s,"0")!=0)
productscount+=atoi(s);/*累加操作*/
else
break; /*停止累加*/
}
t2->productscount=productscount;
head=InsertIntoLink(head,t2->empnumber,t2->productscount);/* 把员工编号和产品数量插入到链表中*/
print(head); /*打印改链表*/
else if(strcmp(s,"2")==0)  /*选择选项2,进行了删除员工信息操作*/
{
printf("input the Employee Number you wanna delete:");
gets(s); /*读取员工编号*/

empnumber=atoi(s); /*Search(head,empnumber); */
head=DeletFromLink(head,empnumber); /*调用删除函数*/
}
else
print(head);
}
return 0;
}
}             这个程序问题错在哪?怎么改呢?欢迎各位大神来试试
搜索更多相关主题的帖子: employee products include number C语言 
2016-06-28 16:11
wanglianyi1
Rank: 11Rank: 11Rank: 11Rank: 11
等 级:贵宾
威 望:14
帖 子:647
专家分:2067
注 册:2015-6-18
收藏
得分:4 
void型函数后面不要加return 0;还有你这个程序缩进格式看的真蛋疼,main类型改为int吧,还有你main里面的if-else你配对看一下,合适吗?程序找来要自己先看看哦

[此贴子已经被作者于2016-6-28 16:56编辑过]

2016-06-28 16:46
黄瑶
Rank: 1
等 级:新手上路
帖 子:3
专家分:0
注 册:2016-6-28
收藏
得分:0 
C:\Cpp1.cpp(156) : error C2601: 'print' : local function definitions are illegal
C:\Cpp1.cpp(174) : error C2601: 'main' : local function definitions are illegal
void print()函数有错;但花括号都有对应,还可以怎么改?
2016-06-28 16:51
八画小子
Rank: 11Rank: 11Rank: 11Rank: 11
等 级:贵宾
威 望:37
帖 子:709
专家分:2063
注 册:2010-11-11
收藏
得分:4 
咋说呢?
我们一般提问题不会把整个代码都贴出来,只会贴出问题的地方。即便因代码的问题找不到出错的范围,那也应该把出现的错误说清楚啊。
你一不说这程序是干啥的,二不说错误范围,三不说发生了什么错误,没人会理你啊。
把你的代码看懂就得花不少时间,搞懂你的意图又得花不少时间,搞明白为啥错了,还得不少时间。这时候才开始帮你解决问题。
你自己说说,你会理这样的人吗?
2016-06-28 16:55
八画小子
Rank: 11Rank: 11Rank: 11Rank: 11
等 级:贵宾
威 望:37
帖 子:709
专家分:2063
注 册:2010-11-11
收藏
得分:0 
看看 print() 前面的函数
2016-06-28 16:59
linlulu001
Rank: 13Rank: 13Rank: 13Rank: 13
等 级:贵宾
威 望:20
帖 子:944
专家分:4047
注 册:2016-4-13
收藏
得分:4 
以下是引用黄瑶在2016-6-28 16:51:38的发言:

C:\Cpp1.cpp(156) : error C2601: 'print' : local function definitions are illegal
C:\Cpp1.cpp(174) : error C2601: 'main' : local function definitions are illegal
void print()函数有错;但花括号都有对应,还可以怎么改?

这两个函数结尾处多了return 0;
2016-06-28 17:02
八画小子
Rank: 11Rank: 11Rank: 11Rank: 11
等 级:贵宾
威 望:37
帖 子:709
专家分:2063
注 册:2010-11-11
收藏
得分:0 
回复 6楼 linlulu001
没事,让人家自己找吧。
2016-06-28 17:05
黄瑶
Rank: 1
等 级:新手上路
帖 子:3
专家分:0
注 册:2016-6-28
收藏
得分:0 
哦,这样啊,真不好意思,新手一个
这是一个职工工作量统计系统(用有序链表存储数据)
void print(),main()函数都是一样的错误,是不是逻辑错误?
void print(TS *head) /*打印函数*/
{
TS *temp,*p1;
int i=1;
temp=head;/*头指针赋值给temp,temp指向链表头*/
printf("\n output the result:\n");
printf("\n order\t\tporductscount\t\tempnumber\n");
     while(temp!=NULL)
     {
       printf("\t%d\t\t%d\t\t\t%d\n",i,temp->productscount,temp->empnumber); /*输出序号i,产品数量,员工编号*/
       i++;
       temp=temp->next; /*指针下移*/
      }
}



void main()
{
TS *CreateLink(TS*); /*声明创建链表的函数*/
TS *InsertIntoLink(); /*声明插入链表的函数*/
TS *DeletFromLink(); /*声明删除函数*/
TS *Search();
void print();/*声明打印链表的函数*/
TS *head;
TS *temp;
TS *t2;
char s[100];
int empnumber=0;
int productscount=0;
int n;
head=NULL;
head=CreateLink(head); /*先创建空链表*/
temp=(TS*)malloc(sizeof(TS));
t2=(TS*)malloc(sizeof(TS));
while(1) /*一个可控制的循环*/
{
LOOP: printf("\t\t**********职工工作量统计系统**********\n\n");
printf("************1 改变职工信息***********\t");
printf("************2删除职工信息***********\n\n");
printf("************3显示职工信息***********\t");
printf("\t\t**********0 退出系统***********\n\n");
printf("your choice:");
gets(s);
if(strcmp(s,"1")!=0&&strcmp(s,"2")!=0&&strcmp(s,"3")!=0)
return 0;/*如果不是1或者2选项,就退出系统*/
      if(strcmp(s,"1")==0)   /*选择选项1,进行改变员工信息操作*/
      {
printf("\nPlease Input you Employee Number And Products Count you are to change!\nthe employee Number :");
gets(s);
empnumber=atoi(s);   /*输入员工编号*/
printf("\nSearching for the number,Please wait.....\n");
temp=Search(head,empnumber);
printf("\nprint the nod of temp: temp.empnumber= %d",temp->empnumber);
printf("\nprint the nod of temp: temp.productscount= %d",temp->productscount);
      if(temp==NULL)
      goto LOOP;
             Else
      {  
t2->empnumber=temp->empnumber;
t2->productscount=temp->productscount; /* memcpy(t2,temp,sizeof(TS));*/
printf("\nprint the nod of temp: temp.empnumber= %d",temp->empnumber);
printf("\nprint the nod of temp: temp.productscount= %d",temp->productscount);
printf("\nprint the nod of temp: t2.empnumber= %d",t2->empnumber);
printf("\nprint the nod of temp: t2.productscount= %d",t2->productscount);
t2->next=NULL;
printf("\nbefore Delete the temp node....\n");
print(head);
head=DeletFromLink(head,t2->empnumber);
printf("\nafter delete the temp node....\n");
print(head);
      }   
     }
                productscount+=t2->productscount;
                while(1) /*改循环实现产品数量累加计算*/
{
printf("Would you like to input more products count? if not,please type 0\n your Input: ");
gets(s);
if(strcmp(s,"0")!=0)
productscount+=atoi(s);/*累加操作*/
else
break; /*停止累加*/
}
t2->productscount=productscount;
head=InsertIntoLink(head,t2->empnumber,t2->productscount);/* 把员工编号和产品数量插入到链表中*/
print(head); /*打印改链表*/
else if(strcmp(s,"2")==0)  /*选择选项2,进行了删除员工信息操作*/
{
printf("input the Employee Number you wanna delete:");
gets(s); /*读取员工编号*/

empnumber=atoi(s); /*Search(head,empnumber); */
head=DeletFromLink(head,empnumber); /*调用删除函数*/
}
else
print(head);
}
}

2016-06-28 17:24
低调低调
Rank: 3Rank: 3
来 自:四川省成都市
等 级:论坛游侠
威 望:1
帖 子:66
专家分:103
注 册:2016-6-23
收藏
得分:4 
我只想说这个格式实在太考验我的眼力了 所以我选择死亡
2016-06-28 20:03
wanglianyi1
Rank: 11Rank: 11Rank: 11Rank: 11
等 级:贵宾
威 望:14
帖 子:647
专家分:2067
注 册:2015-6-18
收藏
得分:0 
回复 8楼 黄瑶
void型的函数是没有返回值的,你后面加return 0;返回0,会不会出错?所以void型函数的话要把最后的return语句去掉。还有main改成int,不然有的编译器会警告。至于你说的花括号对应这个要自己检查,我说的是if-else一一对应。你可以把你的代码放到编译器里运行下看看错误提示;
main函数开始那几个函数声明可以去掉,你的自定义函数都在main前面,没必要声明,后面可以直接调用。
你的缩进格式要好好搞下,看的真难受。你main函数里面的if-else的逻辑关系你自己一个一个匹配对应下看看,就知道错在哪了

[此贴子已经被作者于2016-7-4 15:41编辑过]

2016-06-29 08:49
快速回复:C语言调试
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.025864 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved