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

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里是半角的。

    评论

报告相同问题?

悬赏问题

  • ¥15 运筹学排序问题中的在线排序
  • ¥15 关于docker部署flink集成hadoop的yarn,请教个问题 flink启动yarn-session.sh连不上hadoop,这个整了好几天一直不行,求帮忙看一下怎么解决
  • ¥30 求一段fortran代码用IVF编译运行的结果
  • ¥15 深度学习根据CNN网络模型,搭建BP模型并训练MNIST数据集
  • ¥15 C++ 头文件/宏冲突问题解决
  • ¥15 用comsol模拟大气湍流通过底部加热(温度不同)的腔体
  • ¥50 安卓adb backup备份子用户应用数据失败
  • ¥20 有人能用聚类分析帮我分析一下文本内容嘛
  • ¥30 python代码,帮调试,帮帮忙吧
  • ¥15 #MATLAB仿真#车辆换道路径规划