|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
- #include<stdio.h>
- #include<stdlib.h>
- struct stud_node
- {
- int num;
- char name[20];
- int grade;
- struct stud_node *next;
- };
- struct stud_node *Creat_Stud_Doc();
- struct stud_node * InsertDoc(struct stud_node *head,struct stud_node *p);
- int main()
- {
- int choice;
- struct stud_node *head;
- do
- {
- printf("请输入您要执行的操作:");
- scanf("%d",&choice);
- switch(choice)
- {
- case 1:
- head = Creat_Stud_Doc();
- break;
- }
- }while(choice!=0);
- }
- struct stud_node *Creat_Stud_Doc()
- {
- struct stud_node *head,*p;
- int size;
- int num;
- char name[20];
- int grade;
- size = sizeof(struct stud_node);
- printf("请输入学生信息:");
- scanf("%d%s%d",&num,name,&grade);
- head = NULL;
- while(num != 0)
- {
- p = (struct stud_node *)malloc(size);
- p ->num = num;
- strcpy(p ->num,num);
- p ->grade = grade;
- head = InsertDoc(head,p);
- scanf("%d%s%d",&num,name,&grade);
- }
- return head;
- };
- struct stud_node *InsertDoc(struct stud_node *head, struct stud_node *p)
- {
- struct stud_node *str,*str1,*str2;
- str = p;
- str2 = head;
- if(head == NULL)
- {
- head = str;
- head ->next = NULL;
- }
- else
- {
- while((str ->num > str2 ->num) && (str2 ->next != NULL))
- {
- str1 = str2;
- str2 = str2 ->next;
- }
- if(str ->num <= str2 ->num)
- {
- if(str2 == head)
- {
- head = str;
- }
- else
- {
- str1->next = str;
- }
- str->next ->str2;
- }
- else
- {
- str2 = str;
- str2->next = NULL;
- }
- }
- return head;
- };
复制代码
写的链表增加和插入,但是编译出错,大神帮忙看一下哪里出错?
第50行,strcpy函数需要include一个库文件string.h
另外,该函数用于字符串复制,你应该是打错了,估计你是想把name复制给p->name
第88行,赋值运算符=写错了,写成 -> 了
我只看了编译错误,没有逻辑运行是否正确
这些应该能够在编译给出的错误提示中看出来啊。看不懂编译的错误提示?
|
|