zhehuii 2018-10-07 15:31 采纳率: 0%
浏览 1633

scanf输入数后输出的数为什么不一样?

#include
#include
#define LEN sizeof(struct Student)

struct Student //声明结构体
{int num;
int score;
struct Student *next;
};

int n;//全局变量

struct Student *creat(void);//声明函数
void print(struct Student *head);//声明函数

struct Student *creat(void) //定义函数
{struct Student *head;
struct Student *p1,*p2;
p1=p2=(struct Student *)malloc(LEN);
n=0;
head=NULL;
scanf("%d,%d",&p1->num,&p1->score);
fflush(stdin);
while(p1->num!=0)
{ n++;
if(n==1) head=p1;
else p2->next=p1;
p2=p1;
p1=(struct Student *)malloc(LEN);
scanf("%d,%d",&p1->num,&p1->score);
fflush(stdin);
}
p2->next=NULL;
return(head);
}

void print(struct Student *head) //定义输出函数
{struct Student *p;
printf("\nNow,These %d records are:\n",n);
p=head;
if(head!=NULL)
do
{printf("%d %d\n",p->num,p->score);
p=p->next;
}while(p!=NULL);
}

int main()//主函数
{struct Student *pt;
pt=creat();
print(pt);
return 0;
}图片说明

  • 写回答

1条回答 默认 最新

  • threenewbee 2018-10-07 15:45
    关注

    程序没有问题,但是你输入的12和78之间(以及下面)的逗号是全角的,而你scanf里是半角的。

    评论

报告相同问题?