| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 932 人关注过本帖
标题:为什么我的程序不可以运行阿,各位大哥大姐帮忙找找
取消只看楼主 加入收藏
shen476102493
Rank: 1
等 级:新手上路
帖 子:3
专家分:0
注 册:2008-11-12
收藏
 问题点数:0 回复次数:0 
为什么我的程序不可以运行阿,各位大哥大姐帮忙找找
#include<string.h>
#include<stdio.h>
#include<malloc.h>
#include<stdlib.h>
#define N 3
#define ST struct student
struct student
{
    char name[20];
    int age;
    struct student *next;
};

ST *creat(int n)
{
   ST *h,*p,*s;
   
   for(int i=0;i<N;i++)
   {
   s=(ST *)malloc(sizeof(ST));
   printf("please input name and age\n");
   scanf("%s%d",&s->name,&s->age);
  
   if(i==0)
      p=h=s;
   else
       p->next=s;
       s->next=NULL;
       p=s;
}
return(h);
}

ST *search(ST *h,char *n)
{
    ST *p;
    char *m;

    p=h->next;
    while(p!=NULL)
    {
        m=p->name;
        if(strcmp(m,n)==0)
            return(p);
        else p=p->next;
    }
    if(p==NULL)
    

    /*
     while(p->name!=n&&p->next!=NULL)
         p=p->next;
     if(p->name==n) return(p);
     if(p->name!=n&&p->next==NULL)*/
         printf("node %d has not been found!\n",n);
}

ST *search2(ST *h,char *x)
{
    ST *p,*s;
    char *y;
    p=h->next;
    s=h;
    while(p!=NULL)
    {
        y=p->name;
        if(strcmp(y,x)==0)
            return(s);
        else
        {
            p=p->next;
            s=s->next;

        }
    }
    if(p==NULL)
        printf("没有查到该数据! ");
}


void insert(ST *p)
{
    char stuname[20];
    ST *s;
    if((s=(ST *)malloc(sizeof(ST)))==NULL)
    {
        printf("不能分配空间!");
        exit(0);
    }
    printf("please input name and age:");
    scanf("%s%d",stuname,&s->age);
    strcpy(s->name,stuname);
    s->next=p->next;
    p->next=s;
}


void del(ST *x,ST *y)
{
    ST *s;
    s=y;
    x->next=y->next;
    free(s);
}


void print(ST *h)
{
    ST *p;
    p=h->next;
    printf("数据信息为:\n");
    while(p!=NULL)
    {
        printf("姓名:%s\t年龄:%d\n",p->name,p->age);
        p=p->next;
    }
    p=p->next;
}


void quit()
{
    exit(0);
}

void menu(void)
{
    printf("\t\t\t 单链表c语言实现实例\n\n");
    printf("\t\t\t\t++++++++++++++++++++\n");
    printf("\t\t\t+  [1] 建 立 新 表      +\n");
    printf("\t\t\t+  [2] 插 入 数 据      +\n");
    printf("\t\t\t+  [3] 删 除 数 据      +\n");
    printf("\t\t\t+  [4] 打 印 数 据      +\n");
    printf("\t\t\t+  [5] 退 出            +\n");
    printf("\t\t\t+  未建立新表,请先建立 +\n");
    printf("\t\t\t+ + + + + + + + + + + + +\n");
    printf("\t\t\t  输入你的选项(1-5):");
}
void main()
{
int choose;
ST *head,*searchpoint,*forepoint;
char fullname[20];
while(1)
{
menu();
scanf("%d",&choose);
switch(choose)
{
case 1:head=creat(N);
break;
 
case 2: printf("输入你要在哪个人后面插入:");
scanf("%s",fullname);
searchpoint=search(head,fullname);
printf("你所查找的人的姓名为:%s",*&searchpoint->name);
insert(searchpoint);
print(head);
printf("\n按回车键回到主菜单。");
getchar();getchar();
break;

case 3:print(head);
printf("\n输入你所要删除的人的姓名:");
scanf("%s",fullname);
searchpoint=search(head,fullname);
forepoint=search2(head,fullname);
del(forepoint,searchpoint);
break;

case 4:print(head);
printf("\n按回车键回到主菜单。");
getchar();getchar();
break;

case 5:quit();
break;
default:printf("你输入了非法字符!按回车键回到主菜单。");
menu();
getchar();
}
}
}
搜索更多相关主题的帖子: 大姐 运行 
2008-11-12 11:24
快速回复:为什么我的程序不可以运行阿,各位大哥大姐帮忙找找
数据加载中...
 
   



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

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