当前位置: 代码迷 >> C语言 >> 大家帮忙看看什么问题
  详细解决方案

大家帮忙看看什么问题

热度:194   发布时间:2007-12-21 22:17:15.0
大家帮忙看看什么问题
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#define NULL 0
struct node
{
    char number[15];
    char name[10];
    char sex;
    struct node *link;
}
struct node * creattab(int n)
{
    int i;
    struct node *phead,*ptail,*pnew;
    pnew=(struct node *)malloc(sizeof(struct node));
    if(pnew==NULL)
    {
        printf("内存不足!\n");
        exit(1);
    }
    else
    {
        printf("Input number:");
        gets(pnew->number);
        printf("Input name:");
        gets(pnew->name);
        printf("Input sex:");
        gets(pnew->sex);
        pnew->link=NULL;
        phead=pnew;
        ptail=pnew;
    }
    for(i=1;i<n;i++)
    {
        pnew=(struct node *)malloc(sizeof(struct node));
        if(pnew==NULL)
        {
            printf("内存不足!\n");
            exit(1);
        }
        else
        {
            printf("Input number:");
            gets(pnew->number);
            printf("Input name:");
            gets(pnew->name);
            printf("Input sex:");
            gets(pnew->sex);
            pnew->link=NULL;
            phead->link=pnew;
            ptail->link=pnew;
            ptail=pnew;
        }
    }
    return(phead);
}
int main()
{
    struct node *creattab(int n);
    int m=3;
    struct node *phead,*pnew,*p;
    p=creattab(m);
    phead=p;
    return 0;
}
这是一个做链表的程序,我调了很多次都说struct node unexpected.我实在找不到有什么错误,
请个位多多指教,谢谢了!
----------------解决方案--------------------------------------------------------
定义结构之后要写一个分号
----------------解决方案--------------------------------------------------------
哦!!!
恍然醒悟,怎么就没看到呢
谢谢哈
----------------解决方案--------------------------------------------------------
  相关解决方案