回 帖 发 新 帖 刷新版面

主题:帮忙调一下这个程序.

各位好,谁能帮我调一下这个程序,我调了好久,老调不好.




#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#define NUll 0
#define LEN sizeof(struct stu)

struct stu          //定义结构体
{
    int num;
    char name[10];
    char sex;
    float Chinese;
    float English;
    float Computer;
    struct stu *next;
};

int n;


struct stu *creat()                         //定义链表
{   
    
    struct stu *head,*p1,*p2;    
    n=0;                    
    p1=p2=(struct stu *)malloc(LEN);    
    scanf("%d%s%s%g%g%g",&p1->num,p1->name,&p1->sex,&p1->Chinese,&p1->English,&p1->Computer);
    head=NULL;      
    while(p1->num!=0)
    {
        n=n+1;       
        if (n==1)     
            head=p1;                           
        else
            p2->next=p1;   
        p2=p1;  
        p1=( struct stu *)malloc(LEN);  
        scanf("%d%s%s%g%g%g",&p1->num,p1->name,&p1->sex,&p1->Chinese,&p1->English,&p1->Computer);  
    }
    p2->next=NULL;         
    return(head);                        
}


void print(struct stu *head)                   //打印函数
{    struct stu *p1;
    p1=head;
    printf("\n总共有%d条记录:\n",n);
        
    while(p1!=NULL)
    {    printf("%d%s%s%g%g%g\n",p1->num,p1->name,p1->sex,p1->Chinese,p1->English,p1->Computer);
        p1=p1->next;
    }
}

main()
{
struct stu *head;
head=creat();
print(head);
}

回复列表 (共1个回复)

沙发

函数必须返回一个值
可能要在函数原型中给出返回值的类型

我来回复

您尚未登录,请登录后再回复。点此登录或注册