| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 369 人关注过本帖
标题:为什么会提示缺少头文件呢?
只看楼主 加入收藏
zyx1989
Rank: 1
等 级:新手上路
帖 子:86
专家分:2
注 册:2011-9-17
结帖率:83.33%
收藏
已结贴  问题点数:10 回复次数:3 
为什么会提示缺少头文件呢?
#include<stdio.h>
#include<malloc.h>
#include<stdlib.h>
#include<string.h>
typedef struct student
{
    int num;
   
    struct student *link;
}stud;

 stud* creat(int n)
{
    stud *h,*p;
    int i;
    h=(stud *)malloc(sizeof(stud));
    if(h==NULL)
    {
        printf("not enough memory!");
        return(0);
    }
    h=NULL;
    for(i=0;i<=n;i++)
    {
        
        
        if((p=(struct student *)malloc(sizeof(stud)))==NULL)
            
            
            
        {
            printf("内存不足!");
            return(0);
        }
        scanf("%d",&p->num);
        
        p->link=h;
        h=p;
        
    }
    return(h);
}
   
  void search(stud *h)
  {
    stud *p;
    int m;
    printf("请输入需查找数据!");
    scanf("%d",&m);
    p=h;
    while(p!=NULL)
    {
   
        if(m==p->num)
        {printf("%d\n",m);
        
         break;
        }
        else
         p=p->link;
    }
         
   
   
   
  }
  stud *delete(stud *h)
  {
      stud *q,*p;
      p=h;
      int n;
      q=h->link;
      printf("请输入要删除的数字!");
      scanf("%d",&n);
      
      while(p!=NULL&&q!=NULL)
      {
          p=p->link;
          q=q->link;
          if(n==q->num)
          p->link=q->link;
          else if
          (n==p->num)
           q=h;
          printf("删除成功!");
          free(p);
      }
      return(h);
  }
 void print(stud *h)
 {
     stud *p;
     p=h;
     while(p!=NULL)
     {
         printf("%d",p->num);
         p=p->link;
     }
 }
void main()
{
    struct student *h;
   
    h=(struct student *)creat(3);
   
    search(h);
    delete(h);
    print(h);
}

搜索更多相关主题的帖子: include memory return 
2011-09-25 16:07
czsbc
Rank: 10Rank: 10Rank: 10
等 级:青峰侠
帖 子:469
专家分:1700
注 册:2008-12-13
收藏
得分:5 
你用的什么编译器?

h=(stud *)malloc(sizeof(stud));
     if(h==NULL)
     {
         printf("not enough memory!");
         return(0);
     }
     h=NULL;
 这里内存分配了有啥用?
2011-09-25 16:09
pauljames
Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19
等 级:千里冰封
威 望:9
帖 子:1555
专家分:10000
注 册:2011-5-8
收藏
得分:5 
跟你的编程环境和编译器有关

经常不在线不能及时回复短消息,如有c/单片机/运动控制/数据采集等方面的项目难题可加qq1921826084。
2011-09-25 16:10
zyx1989
Rank: 1
等 级:新手上路
帖 子:86
专家分:2
注 册:2011-9-17
收藏
得分:0 
h=NULL,是初始化指针,下面不是创建链表吗
2011-09-25 16:21
快速回复:为什么会提示缺少头文件呢?
数据加载中...
 
   



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

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