标题:请哪位可以告诉我我的c语言哪里有问题,
取消只看楼主
yujinrun
Rank: 1
等 级:新手上路
帖 子:1
专家分:0
注 册:2022-11-23
 问题点数:0 回复次数:0 
请哪位可以告诉我我的c语言哪里有问题,
#include<stdio.h>
#include<stdlib.h>
//定义全局变量
int count;
//定义结构体
struct school
{
    char name[50];
    char gender;
    int age;
    int number;
    struct school *pnext;
};
 //创建链表
 
struct school* Create()
{
    count =0;
    struct school *phead=NULL;
    struct school *pnew,*pend;
    pnew=pend=(struct school*)malloc(sizeof(struct school));
    printf("请按规范输入学生的姓名,性别,年龄以及学号!\n");
    printf("请输入学生姓名:\n");
    scanf("%s",&pnew->name);
    printf("请输入学生姓别:\n");
    scanf("%c",&pnew->gender);
    printf("请输入学生年龄:\n");
    scanf("%d",&pnew->age);
    printf("请输入学生学号:\n");
    scanf("%d",&pnew->number);
    while(pnew->number!=0)
    {
        count++;
        if(count==1)
        {
            pnew->pnext=phead;
            phead=pnew;
            pend=pnew;
        }
        else
        {
            pnew->pnext=NULL;
            pend->pnext=pnew;
            pend=pnew;
        }
        pnew=(struct school*)malloc(sizeof(struct  school));
        printf("请输入学生姓名:\n");
        scanf("%s",&pnew->name);
        printf("请输入学生姓别:\n");
        scanf("%c",&pnew->gender);
        printf("请输入学生年龄:\n");
        scanf("%d",&pnew->age);
        printf("请输入学生学号:\n");
        scanf("%d",&pnew->number);
    }
    free(pnew);
    return phead;
        
}
//输出链表
void print(struct school *phead)
{
    struct school* itemp;
    int i=1;
    itemp=phead;
    while(itemp!=NULL)
    {
        printf("第%d位同学的资料\n",i);
        printf("学生姓名:%s",itemp->name);
        printf("学生性别:%s",itemp->gender);
        printf("学生年龄:%s",itemp->age);
        printf("学生学号:%s",itemp->number);
        itemp=itemp->pnext;
    }
   
 }
 int main()
 {
     
     struct school* phead;
     phead=Create();   
     print(phead);
     return 0;
 }
就是输入时候的问题
搜索更多相关主题的帖子: scanf 输入 学生 printf struct 
2022-11-23 17:46



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-510755-1-1.html




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

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