求助!程序运行,输入数据后,打印操作跳过了,看不出什么问题
#include<stdio.h>#include<stdlib.h>
#include<string.h>
struct student
{
int num;
int score;
struct student *next;
};
struct student *chuangjian() {
struct student *head;
struct student *p1, *p2;
head = (struct student*)malloc(sizeof(struct student));
int n;
head->next = NULL;
p2 = head;
printf("input the num:");
scanf("%d", &n);
while(n != 0) {
p1 = (struct student*)malloc(sizeof(struct student));
p1->num = n;
printf("input the score:");
scanf("%d", &p1->score);
printf("\n");
p1->next = NULL;
p1 = p1->next;
p2 = p1;
printf("input the num:");
scanf("%d", &n);
}
return head;
}
void print(struct student *head)
{
struct student *a;
a=head->next;
while(a)
{printf("%d\t%d\n",a->num,a->score);
a->next=a;}
}
struct student *del(struct student *head, int num) {
struct student *p1, *p2;
if(head = NULL) {
printf("\nthis is null!\n");
goto END;
}
p1 = head;
while(p1->num != num && p1->next != NULL) {
p2 = p1;
p1 = p1->next;
}
if(num == p1->num) {
p2->next = p1->next;
printf("\nDelete num:%d succeed!\n", num);
}
else
{
printf("%d not been found!\n", num);
}
END:
return head;
}
int main() {
struct student *head=NULL;
int n;
head = chuangjian();
print(head);
printf("input the num for delete:");
scanf("%d", &n);
del(head, n);
return 0;
} 我运行了你的程序后没有跳过,应该是编程环境设置的问题。你可试一下system(“pause”),记得加上头文件include<windows.h>.还有程序中尽量少使用go语句,虽然编写方便,但不利于代码的复用性,对其维护困难,可读性差。
页:
[1]