| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 835 人关注过本帖
标题:
只看楼主 加入收藏
lrx2014
Rank: 1
等 级:新手上路
帖 子:39
专家分:0
注 册:2014-4-11
结帖率:70%
收藏
已结贴  问题点数:10 回复次数:13 
#include<stdio.h>
#include<stdlib.h>
#include"string.h"
#define NULL 0

    int num,i=0,m,kind;
    float jbgzl,jbgz,shangxueqi,gongzi=0;  //基本工作量,基本工资,上学期工作量,工资
    float xzbt,sysbz,ksf;     //行政补贴,实验室补助,课时费
struct node
{
    int num;
    char name[20];
    int leibie;
    float months[12];
    struct node *next;
};
struct node *creat()
{   
    struct node *p1,*p2;
    struct node *head;
    int n;
    head=(struct node *)malloc(sizeof(struct node));//设置一个空的头结点
    n=0;
    head->num=n;
    p2=head;
    printf("请输入员工信息(编号为0退出初始化)\n");
    printf("编号:");
    scanf("%d",&num);
    while(num!=0)
    {
        p1=(struct node *)malloc(sizeof(struct node));
         p1->next=NULL;
        p1->num=num;
        printf("姓名:");
        scanf("%s",&p1->name);
        printf("员工类别(1-5):");
        c:scanf("%d",&kind);
        if(kind<1||kind>5)
        {
            printf("错误!请重新选择(1-5):");
            goto c;

        }
        p1->leibie=kind;
        switch(kind)
        {
        case 1:
                jbgz=850;
                jbgzl=180;
                printf("请输入该员工上学期工作量:");
                scanf("%f",&shangxueqi);
                ksf=(shangxueqi-jbgzl)*30;
                gongzi=jbgz+ksf;
                printf("需要录入几个月的工资(1-12):");
                scanf("%d",&m);
                for(i=0;i<12;i++)
                    p1->months[i]='\0';
                for(i=0;i<m;i++)
                    p1->months[i]=gongzi;
                printf("录入成功,请继续录入下一个员工的信息(输入0退出初始化)\n");
                break;
            case 2:
                jbgz=650;
                sysbz=200;
                gongzi=jbgz+sysbz;
                for(i=0;i<12;i++)
                    p1->months[i]='\0';
                printf("需要录入几个月的工资(1-12):");
                scanf("%d",&m);
                for(i=0;i<m;i++)
                    
                    p1->months[i]=gongzi;
                printf("录入成功,请继续录入下一个员工的信息(输入0退出初始化)\n");
                break;
            case 3:
                jbgz=750;
                xzbt=360;
                gongzi=jbgz+xzbt;
                for(i=0;i<12;i++)
                    p1->months[i]='\0';
                printf("需要录入几个月的工资(1-12):");
                scanf("%d",&m);
                for(i=0;i<m;i++)
                    p1->months[i]=gongzi;
                printf("录入成功,请继续录入下一个员工的信息(输入0退出初始化)\n");
                break;
            case 4:
                jbgz=850;
                jbgzl=180;
                sysbz=200;
                printf("请输入该员工上学期工作量");
                scanf("%f",&shangxueqi);
                ksf=(shangxueqi-jbgzl)*30;
                gongzi=jbgz+ksf+sysbz;
                for(i=0;i<12;i++)
                    p1->months[i]='\0';
                printf("需要录入几个月的工资(1-12):");
                scanf("%d",&m);
                for(i=0;i<m;i++)
                    
                    p1->months[i]=gongzi;
                printf("录入成功,请继续录入下一个员工的信息(输入0退出初始化)\n");
                break;
            case 5:
                jbgz=750;
                xzbt=360;
                jbgzl=180;
                printf("请输入该员工上学期工作量");
                scanf("%f",&shangxueqi);
                ksf=(shangxueqi-jbgzl)*30;
                gongzi=jbgz+xzbt+ksf;
                for(i=0;i<12;i++)
                    p1->months[i]='\0';
                printf("需要录入几个月的工资(1-12):");
                scanf("%d",&m);
                for(i=0;i<m;i++)
                    
                    p1->months[i]=gongzi;
                printf("录入成功,请继续录入下一个员工的信息(输入0退出初始化)\n");
                break;
        }
        
            p2->next=p1;
        
             p2=p1;
        printf("编号:");
        scanf("%d",&num);

  
    }
    return head;
}
void insert(struct node *head)
{
    struct node *p,*p1;
    p=head->next;   //指向链表头结点
    printf("请输入员工信息(编号为0返回主菜单)\n");
    printf("编号:");
    scanf("%d",&num);
    while(num!=0)
    {
        p1=(struct node *)malloc(sizeof(struct node));
         p1->next=NULL;
        p1->num=num;
        printf("姓名:");
        scanf("%s",&p1->name);
        printf("员工类别(1-5):");
        c:scanf("%d",&kind);
        if(kind<1||kind>5)
        {
            printf("错误!请重新选择(1-5):");
            goto c;

        }
        p1->leibie=kind;
        switch(kind)
        {
        case 1:
                jbgz=850;
                jbgzl=180;
                printf("请输入该员工上学期工作量:");
                scanf("%f",&shangxueqi);
                ksf=(shangxueqi-jbgzl)*30;
                gongzi=jbgz+ksf;
                printf("需要录入几个月的工资(1-12):");
                scanf("%d",&m);
                for(i=0;i<12;i++)
                    p1->months[i]='\0';
                for(i=0;i<m;i++)
                    p1->months[i]=gongzi;
                printf("添加成功,请继续添加下一个员工的信息(输入0返回主菜单)\n");
                break;
            case 2:
                jbgz=650;
                sysbz=200;
                gongzi=jbgz+sysbz;
                for(i=0;i<12;i++)
                    p1->months[i]='\0';
                printf("需要录入几个月的工资(1-12):");
                scanf("%d",&m);
                for(i=0;i<m;i++)
                    
                    p1->months[i]=gongzi;
                printf("添加成功,请继续添加下一个员工的信息(输入0返回主菜单)\n");
                break;
            case 3:
                jbgz=750;
                xzbt=360;
                gongzi=jbgz+xzbt;
                for(i=0;i<12;i++)
                    p1->months[i]='\0';
                printf("需要录入几个月的工资(1-12):");
                scanf("%d",&m);
                for(i=0;i<m;i++)
                    p1->months[i]=gongzi;
                printf("添加成功,请继续添加下一个员工的信息(输入0返回主菜单)\n");
                break;
            case 4:
                jbgz=850;
                jbgzl=180;
                sysbz=200;
                printf("请输入该员工上学期工作量:");
                scanf("%f",&shangxueqi);
                ksf=(shangxueqi-jbgzl)*30;
                gongzi=jbgz+ksf+sysbz;
                for(i=0;i<12;i++)
                    p1->months[i]='\0';
                printf("需要录入几个月的工资(1-12):");
                scanf("%d",&m);
                for(i=0;i<m;i++)
                    
                    p1->months[i]=gongzi;
                printf("添加成功,请继续添加下一个员工的信息(输入0返回主菜单)\n");
                break;
            case 5:
                jbgz=750;
                xzbt=360;
                jbgzl=180;
                printf("请输入该员工上学期工作量:");
                scanf("%f",&shangxueqi);
                ksf=(shangxueqi-jbgzl)*30;
                gongzi=jbgz+xzbt+ksf;
                for(i=0;i<12;i++)
                    p1->months[i]='\0';
                printf("需要录入几个月的工资(1-12):");
                scanf("%d",&m);
                for(i=0;i<m;i++)
                    
                    p1->months[i]=gongzi;
                printf("添加成功,请继续添加下一个员工的信息(输入0返回主菜单)\n");
                break;
        }
        while(p->next!=NULL)   
            p=p->next;    //指向下一个结点
        if(p->next==NULL)
            p->next=p1; //将新结点链入尾结点
        p=p1;      
        printf("编号:");
        scanf("%d",&num);   
    }
 

}
struct node *del(struct node *head)
{
   struct node *p,*r;
   char string[20];
   char *name;
   name=string;
   int s;
   p=head;
   if(p==NULL)
   {
       printf("该链表为空,无法删除");
       return head;
   }
  
   while(1)
   {
       printf("\t  ┏━━━━━━━━━━━━━━━━━━━━━━━━━━┓\n");
       printf("\t                                                      ┃\n");
       printf("\t                     1.按编码删除                     ┃\n");
       printf("\t                                                      ┃\n");
       printf("\t                     2.按名字删除                     ┃\n");
       printf("\t                                                      ┃\n");
       printf("\t                     3.                           ┃\n");
       printf("\t                                                      ┃\n");
       printf("\t  ┗━━━━━━━━━━━━━━━━━━━━━━━━━━┛\n");
       printf("请选择(1-3)==>");
z:       scanf("%d",&s);
       if(s>3||s<1)
       {
           printf("选择错误,请重新选择(1-3)=>");
           goto z;
       }
       switch(s)
       {
       case 1:
            p=head->next;
            printf("请输入要删除的员工编号:");
               scanf("%d",&num);
            while(num!=p->num&&p->next!=NULL)   
            {
                r=p;
                p=p->next;
            }
            if(num==p->num)
            {
                 r->next=p->next;
                 printf("删除成功\n");
            }
   
              else
             printf("没有该员工信息\n");
            break;
       case 2:
            p=head->next;
            printf("请输入要删除的员工姓名:");
               scanf("%s",&string);
            while(strcmp(p->name,name)!=0&&p->next!=NULL)   
            {
                r=p;
                p=p->next;
            }
            if(strcmp(p->name,name)==0)
            {
               
                 r->next=p->next;
                 printf("删除成功\n");
            }
   
              else
             printf("没有该员工信息\n");
            break;
       case 3:
           return head;
           break;
       }
   }

        return head;
   

            
   
}
struct node *xiugai(struct node *head)
{
    struct node *p1;
    char string[20];
    char *name;
    int s;
    name=string;
    p1=head->next;
    while(1)
    {
       printf("\t  ┏━━━━━━━━━━━━━━━━━━━━━━━━━━┓\n");
       printf("\t                                                      ┃\n");
       printf("\t                     1.按编码查找                     ┃\n");
       printf("\t                                                      ┃\n");
       printf("\t                     2.按名字查找                     ┃\n");
       printf("\t                                                      ┃\n");
       printf("\t                     3.                           ┃\n");
       printf("\t                                                      ┃\n");
       printf("\t  ┗━━━━━━━━━━━━━━━━━━━━━━━━━━┛\n");
       printf("请选择(1-3)==>");
z:       scanf("%d",&s);
       if(s>3||s<1)
       {
           printf("选择错误,请重新选择(1-3)=>");
           goto z;
       }
       switch(s)
       {
       case 1:
            p1=head->next;
            printf("请输入要修改的员工编号:");
            scanf("%d",&num);
             while(p1->num!=num&&p1->next!=NULL)
             p1=p1->next;
            if(p1->num==num)
            {
                printf("该员工本来信息:\n");
                printf("编号:%d\n",p1->num);
                   printf("姓名:%s\n",p1->name);
                  printf("类别:%d\n",p1->leibie);
                  for(i=0;i<12;i++)
                 printf("%d月工资:%f\n",i+1,p1->months[i]);
                  printf("请重新输入该员工信息:");
                printf("编号:");
                  scanf("%d",&p1->num);
                 printf("姓名:");
                scanf("%s",&p1->name);
                 printf("员工类别(1-5):");
                c:scanf("%d",&kind);
                  if(kind<1||kind>5)
                {
                      printf("错误!请重新选择(1-5):");
                   goto c;

                }
                p1->leibie=kind;
                switch(kind)
                {
                case 1:
                    jbgz=850;
                     jbgzl=180;
                      printf("请输入该员工上学期工作量:");
                    scanf("%f",&shangxueqi);
                    ksf=(shangxueqi-jbgzl)*30;
                    gongzi=jbgz+ksf;
                    printf("需要录入几个月的工资(1-12):");
                    scanf("%d",&m);
                    for(i=0;i<12;i++)
                    p1->months[i]='\0';
                    for(i=0;i<m;i++)
                    p1->months[i]=gongzi;
                     printf("修改成功\n");
                    break;
                case 2:
                      jbgz=650;
                    sysbz=200;
                    gongzi=jbgz+sysbz;
                    for(i=0;i<12;i++)
                    p1->months[i]='\0';
                     printf("需要录入几个月的工资(1-12):");
                    scanf("%d",&m);
                    for(i=0;i<m;i++)
                    
                    p1->months[i]=gongzi;
                     printf("修改成功\n");
                     break;
               case 3:
                    jbgz=750;
                    xzbt=360;
                     gongzi=jbgz+xzbt;
                    for(i=0;i<12;i++)
                    p1->months[i]='\0';
                    printf("需要录入几个月的工资(1-12):");
                    scanf("%d",&m);
                    for(i=0;i<m;i++)
                    p1->months[i]=gongzi;
                    printf("修改成功\n");
                    break;
                case 4:
                      jbgz=850;
                    jbgzl=180;
                    sysbz=200;
                    printf("请输入该员工上学期工作量");
                    scanf("%f",&shangxueqi);
                    ksf=(shangxueqi-jbgzl)*30;
                    gongzi=jbgz+ksf+sysbz;
                    for(i=0;i<12;i++)
                    p1->months[i]='\0';
                     printf("需要录入几个月的工资(1-12):");
                    scanf("%d",&m);
                    for(i=0;i<m;i++)
                    
                    p1->months[i]=gongzi;
                     printf("修改成功\n");
                    break;
                case 5:
                     jbgz=750;
                    xzbt=360;
                    jbgzl=180;
                    printf("请输入该员工上学期工作量");
                    scanf("%f",&shangxueqi);
                    ksf=(shangxueqi-jbgzl)*30;
                    gongzi=jbgz+xzbt+ksf;
                    for(i=0;i<12;i++)
                    p1->months[i]='\0';
                     printf("需要录入几个月的工资(1-12):");
                    scanf("%d",&m);
                     for(i=0;i<m;i++)
                    
                    p1->months[i]=gongzi;
                    printf("修改成功\n");
                    break;
                }
            }
            else
            printf("找不到该员工信息");
            break;
        case 2:
            p1=head->next;
            printf("请输入要修改的员工姓名:");
            scanf("%s",&string);
             while(strcmp(p1->name,name)!=0&&p1->next!=NULL)
             p1=p1->next;
            if(strcmp(p1->name,name)==0)
            {
                printf("该员工本来信息:\n");
                printf("编号:%d\n",p1->num);
                   printf("姓名:%s\n",p1->name);
                  printf("类别:%d\n",p1->leibie);
                  for(i=0;i<12;i++)
                 printf("%d月工资:%f\n",i+1,p1->months[i]);
                printf("请重新输入该员工信息:");
                printf("编号:");
                scanf("%d",&p1->num);
                printf("姓名:");
                 scanf("%s",&p1->name);
                printf("员工类别(1-5):");
              a:scanf("%d",&kind);
                if(kind<1||kind>5)
                {
                 printf("错误!请重新选择(1-5):");
                goto a;

                }
                p1->leibie=kind;
               switch(kind)
               {
                case 1:
                    jbgz=850;
                     jbgzl=180;
                      printf("请输入该员工上学期工作量:");
                    scanf("%f",&shangxueqi);
                    ksf=(shangxueqi-jbgzl)*30;
                    gongzi=jbgz+ksf;
                    printf("需要录入几个月的工资(1-12):");
                    scanf("%d",&m);
                    for(i=0;i<12;i++)
                    p1->months[i]='\0';
                    for(i=0;i<m;i++)
                    p1->months[i]=gongzi;
                     printf("修改成功\n");
                    break;
                case 2:
                      jbgz=650;
                    sysbz=200;
                    gongzi=jbgz+sysbz;
                    for(i=0;i<12;i++)
                    p1->months[i]='\0';
                     printf("需要录入几个月的工资(1-12):");
                    scanf("%d",&m);
                    for(i=0;i<m;i++)
                    
                    p1->months[i]=gongzi;
                     printf("修改成功\n");
                     break;
                case 3:
                    jbgz=750;
                    xzbt=360;
                     gongzi=jbgz+xzbt;
                    for(i=0;i<12;i++)
                    p1->months[i]='\0';
                    printf("需要录入几个月的工资(1-12):");
                    scanf("%d",&m);
                    for(i=0;i<m;i++)
                    p1->months[i]=gongzi;
                    printf("修改成功\n");
                    break;
                case 4:
                      jbgz=850;
                    jbgzl=180;
                    sysbz=200;
                    printf("请输入该员工上学期工作量");
                    scanf("%f",&shangxueqi);
                    ksf=(shangxueqi-jbgzl)*30;
                    gongzi=jbgz+ksf+sysbz;
                    for(i=0;i<12;i++)
                    p1->months[i]='\0';
                     printf("需要录入几个月的工资(1-12):");
                    scanf("%d",&m);
                    for(i=0;i<m;i++)
                    
                    p1->months[i]=gongzi;
                     printf("修改成功\n");
                    break;
                case 5:
                     jbgz=750;
                    xzbt=360;
                    jbgzl=180;
                    printf("请输入该员工上学期工作量");
                    scanf("%f",&shangxueqi);
                    ksf=(shangxueqi-jbgzl)*30;
                    gongzi=jbgz+xzbt+ksf;
                    for(i=0;i<12;i++)
                    p1->months[i]='\0';
                     printf("需要录入几个月的工资(1-12):");
                    scanf("%d",&m);
                     for(i=0;i<m;i++)
                    
                    p1->months[i]=gongzi;
                    printf("修改成功\n");
                    break;
               }
            }
            else
                printf("没找到该员工信息\n");
              break;
        case 3:
            return head;
            break;
              



       }
   }
        return head;
        

}
int printf(struct node *head)
{
   

    struct node *p;
    int i,s1,s;
    char *name;
    char string[20];
    name=string;
    p=head->next;
    if(p==NULL)
    {
       printf("该链表为空\n");
       return 0;
    }
    if(p!=NULL)
b:    while(1)
    {
        p=head->next;
        printf("\t  ┏━━━━━━━━━━━━━━━━━━━━━━━━━━┓\n");
           printf("\t                                                      ┃\n");
        printf("\t                   1.查询全部员工信息                 ┃\n");
        printf("\t                                                      ┃\n");
        printf("\t                   2.查询单个员工信息                 ┃\n");
        printf("\t                                                      ┃\n");
        printf("\t                   3. 返 回 主 菜 单                  ┃\n");
        printf("\t                                                      ┃\n");
        printf("\t  ┗━━━━━━━━━━━━━━━━━━━━━━━━━━┛\n");
        printf("请选择(1-3)==>");
     s:scanf("%d",&m);
        if(m<1||m>3)
        {
               printf("选择错误,请重新选择==>");
            goto s;
        }
        switch(m)
        {
            case 1:
                 do
                 {
                    printf("编号:%d\n",p->num);
                       printf("姓名:%s\n",p->name);
                    printf("类别:%d\n",p->leibie);
                    for(i=0;i<12;i++)
                     printf("%d月工资:%f\n",i+1,p->months[i]);
                    p=p->next;
                 }while(p!=NULL);
                  break;
            case 2:
                while(1)
                {
                printf("\t  ┏━━━━━━━━━━━━━━━━━━━━━━━━━━┓\n");
                  printf("\t                                                      ┃\n");
                printf("\t                     1.按编码查询                     ┃\n");
                printf("\t                                                      ┃\n");
                 printf("\t                     2.按名字查询                     ┃\n");
                printf("\t                                                      ┃\n");
                printf("\t                     3.                           ┃\n");
                printf("\t                                                      ┃\n");
                printf("\t  ┗━━━━━━━━━━━━━━━━━━━━━━━━━━┛\n");
                 printf("请选择(1-3)==>");
                c:scanf("%d",&s1);
                 if(m<1||m>3)
                {
                        printf("选择错误,请重新选择==>");
                     goto c;
                }
                switch(s1)
                {
                case 1:
                        p=head->next;
                        printf("请输入查询员工的编码:==>");
                        scanf("%d",&s);
                         while(p->num!=s&&p->next!=NULL)
                         p=p->next;
                         if(s==p->num)
                        {
                            printf("编号:%d\n",p->num);
                            printf("姓名:%s\n",p->name);
                              printf("类别:%d\n",p->leibie);
                             for(i=0;i<12;i++)
                              printf("%d月工资:%f\n",i+1,p->months[i]);
                        }
                         else
                        printf("找不到该员工信息\n");
                        break;
                case 2:
                        p=head->next;
                        printf("请输入查询员工的姓名:==>");
                        scanf("%s",&string);
                        while(strcmp(p->name,name)!=0&&p->next!=NULL)
                         p=p->next;
                        if(strcmp(p->name,name)==0)
                       {
                            printf("编号:%d\n",p->num);
                              printf("姓名:%s\n",p->name);
                              printf("类别:%d\n",p->leibie);
                            for(i=0;i<12;i++)
                             printf("%d月工资:%f\n",i+1,p->months[i]);
                        }
                       else
                         printf("找不到该员工信息\n");
                        break;
                case 3:
                    goto b;
                    break;
                    
                }
                    }
                break;


             case 3:
                return 0;
                 break;

        }
   
    }
   
    return 0;
}

main()
{
    int i,s=0,b=0;
    struct node *head;
    head=NULL;
    printf("\t\t\t   首次使用请先初始化系统。\n");
    while(1)
    {
    printf("\t  ┏━━━━━━━━━━━━━━━━━━━━━━━━━━┓\n");
    printf("\t                                                      ┃\n");
    printf("\t               欢迎来到XX高校工资管理系统             ┃\n");
    printf("\t                                                      ┃\n");
    printf("\t  ┣━━━━━━━━━━━━━━━━━━━━━━━━━━┫\n");
    printf("\t                                                      ┃\n");
    printf("\t                    1.查询员工信息                    ┃\n");
    printf("\t                                                      ┃\n");
    printf("\t                    2.添加员工信息                    ┃\n");
    printf("\t                                                      ┃\n");
    printf("\t                    3.修改员工信息                    ┃\n");
    printf("\t                                                      ┃\n");
    printf("\t                    4.删除员工信息                    ┃\n");
    printf("\t                                                      ┃\n");
    printf("\t                    5.初 始 化系统                    ┃\n");
    printf("\t                                                      ┃\n");
    printf("\t                    6.退出管理系统                    ┃\n");
    printf("\t                                                      ┃\n");
    printf("\t  ┣━━━━━━━━━━━━━━━━━━━━━━━━━━┫\n");
    printf("\t  ┃类别说明:                                           ┃\n");
    printf("\t            1.教师、2.实验员、3.行政人员              ┃\n");
    printf("\t            4.教师兼职实验员、5.行政人员兼职教师      ┃\n");
    printf("\t  ┗━━━━━━━━━━━━━━━━━━━━━━━━━━┛\n");

    printf("请选择您需要的操作选项(1-5)==>");
    a: scanf("%d",&s);
    if(s>6||s<1)
    {    printf("选择错误!请重新选择(1-5)==>");
        goto a;
    }
    switch(s)
    {
        case 1:
            printf(head);
            break;
        case 2:
            insert(head);
            break;
        
        case 3:
            xiugai(head);
            break;
        case 4:
            del(head);
            break;
        case 5:
            head=creat();
            printf("初始化成功,请继续操作\n");
            break;
        case 6:
            printf("Byebye\n");
            exit(1);
            break;
   
    }
   

   
    }

   





}
搜索更多相关主题的帖子: include 实验室 months 工作量 行政 
2014-06-09 17:48
vvvcuu
Rank: 9Rank: 9Rank: 9
等 级:贵宾
威 望:12
帖 子:353
专家分:1253
注 册:2014-4-22
收藏
得分:2 
大体看了下,  试着编译运行,有几处错误.  难为楼主了,写这么多代码,  近800行.
程序代码:
--------------------配置: mingw5 - CUI Debug, 编译器类型: MinGW--------------------

检查文件依赖性...
正在编译 D:\lili\C-Free\Temp\未命名5.c...
[Warning] D:\lili\C-Free\Temp\未命名5.c:4:1: warning: "NULL" redefined   //NULL重定义
[Warning] F:\C-FREE~1\mingw\lib\gcc\mingw32\342EBD~1.5\include\stddef.h:402:1: warning: this is the location of the previous definition
                                                                        //这是前面定义的位置.
[Error] D:\lili\C-Free\Temp\未命名5.c:587: error: conflicting types for 'printf'        //冲突的类型
[Error] D:\lili\C-Free\Temp\未命名5.c:587: error: conflicting types for 'printf'
[Warning] D:\lili\C-Free\Temp\未命名5.c:598: warning: passing arg 1 of `printf' from incompatible pointer type
                                                                              //printf()函数参数1与指针类型不匹配  (大体意思,不大准确哈,英语不好)
[Warning] D:\lili\C-Free\Temp\未命名5.c:605: warning: passing arg 1 of `printf' from incompatible pointer type
[Warning] D:\lili\C-Free\Temp\未命名5.c:606: warning: passing arg 1 of `printf' from incompatible pointer type
[Warning] D:\lili\C-Free\Temp\未命名5.c:607: warning: passing arg 1 of `printf' from incompatible pointer type
[Warning] D:\lili\C-Free\Temp\未命名5.c:608: warning: passing arg 1 of `printf' from incompatible pointer type
[Warning] D:\lili\C-Free\Temp\未命名5.c:609: warning: passing arg 1 of `printf' from incompatible pointer type
[Warning] D:\lili\C-Free\Temp\未命名5.c:610: warning: passing arg 1 of `printf' from incompatible pointer type
[Warning] D:\lili\C-Free\Temp\未命名5.c:611: warning: passing arg 1 of `printf' from incompatible pointer type
[Warning] D:\lili\C-Free\Temp\未命名5.c:612: warning: passing arg 1 of `printf' from incompatible pointer type
[Warning] D:\lili\C-Free\Temp\未命名5.c:613: warning: passing arg 1 of `printf' from incompatible pointer type
[Warning] D:\lili\C-Free\Temp\未命名5.c:614: warning: passing arg 1 of `printf' from incompatible pointer type
[Warning] D:\lili\C-Free\Temp\未命名5.c:618: warning: passing arg 1 of `printf' from incompatible pointer type
[Warning] D:\lili\C-Free\Temp\未命名5.c:626: warning: passing arg 1 of `printf' from incompatible pointer type 
[Error] D:\lili\C-Free\Temp\未命名5.c:626: error: too many arguments to function `printf'
                                                                      //函数printf的参数太多
[Warning] D:\lili\C-Free\Temp\未命名5.c:627: warning: passing arg 1 of `printf' from incompatible pointer type
[Error] D:\lili\C-Free\Temp\未命名5.c:627: error: too many arguments to function `printf'
[Warning] D:\lili\C-Free\Temp\未命名5.c:628: warning: passing arg 1 of `printf' from incompatible pointer type
[Error] D:\lili\C-Free\Temp\未命名5.c:628: error: too many arguments to function `printf'
[Warning] D:\lili\C-Free\Temp\未命名5.c:630: warning: passing arg 1 of `printf' from incompatible pointer type
[Error] D:\lili\C-Free\Temp\未命名5.c:630: error: too many arguments to function `printf'
[Warning] D:\lili\C-Free\Temp\未命名5.c:637: warning: passing arg 1 of `printf' from incompatible pointer type
[Warning] D:\lili\C-Free\Temp\未命名5.c:638: warning: passing arg 1 of `printf' from incompatible pointer type
[Warning] D:\lili\C-Free\Temp\未命名5.c:639: warning: passing arg 1 of `printf' from incompatible pointer type
[Warning] D:\lili\C-Free\Temp\未命名5.c:640: warning: passing arg 1 of `printf' from incompatible pointer type
[Warning] D:\lili\C-Free\Temp\未命名5.c:641: warning: passing arg 1 of `printf' from incompatible pointer type
[Warning] D:\lili\C-Free\Temp\未命名5.c:642: warning: passing arg 1 of `printf' from incompatible pointer type
[Warning] D:\lili\C-Free\Temp\未命名5.c:643: warning: passing arg 1 of `printf' from incompatible pointer type
[Warning] D:\lili\C-Free\Temp\未命名5.c:644: warning: passing arg 1 of `printf' from incompatible pointer type
[Warning] D:\lili\C-Free\Temp\未命名5.c:645: warning: passing arg 1 of `printf' from incompatible pointer type
[Warning] D:\lili\C-Free\Temp\未命名5.c:646: warning: passing arg 1 of `printf' from incompatible pointer type
[Warning] D:\lili\C-Free\Temp\未命名5.c:650: warning: passing arg 1 of `printf' from incompatible pointer type
[Warning] D:\lili\C-Free\Temp\未命名5.c:657: warning: passing arg 1 of `printf' from incompatible pointer type
[Warning] D:\lili\C-Free\Temp\未命名5.c:663: warning: passing arg 1 of `printf' from incompatible pointer type
[Error] D:\lili\C-Free\Temp\未命名5.c:663: error: too many arguments to function `printf'
[Warning] D:\lili\C-Free\Temp\未命名5.c:664: warning: passing arg 1 of `printf' from incompatible pointer type
[Error] D:\lili\C-Free\Temp\未命名5.c:664: error: too many arguments to function `printf'
[Warning] D:\lili\C-Free\Temp\未命名5.c:665: warning: passing arg 1 of `printf' from incompatible pointer type
[Error] D:\lili\C-Free\Temp\未命名5.c:665: error: too many arguments to function `printf'
[Warning] D:\lili\C-Free\Temp\未命名5.c:667: warning: passing arg 1 of `printf' from incompatible pointer type
[Error] D:\lili\C-Free\Temp\未命名5.c:667: error: too many arguments to function `printf'
[Warning] D:\lili\C-Free\Temp\未命名5.c:670: warning: passing arg 1 of `printf' from incompatible pointer type
[Warning] D:\lili\C-Free\Temp\未命名5.c:674: warning: passing arg 1 of `printf' from incompatible pointer type
[Warning] D:\lili\C-Free\Temp\未命名5.c:680: warning: passing arg 1 of `printf' from incompatible pointer type
[Error] D:\lili\C-Free\Temp\未命名5.c:680: error: too many arguments to function `printf'
[Warning] D:\lili\C-Free\Temp\未命名5.c:681: warning: passing arg 1 of `printf' from incompatible pointer type
[Error] D:\lili\C-Free\Temp\未命名5.c:681: error: too many arguments to function `printf'
[Warning] D:\lili\C-Free\Temp\未命名5.c:682: warning: passing arg 1 of `printf' from incompatible pointer type
[Error] D:\lili\C-Free\Temp\未命名5.c:682: error: too many arguments to function `printf'
[Warning] D:\lili\C-Free\Temp\未命名5.c:684: warning: passing arg 1 of `printf' from incompatible pointer type
[Error] D:\lili\C-Free\Temp\未命名5.c:684: error: too many arguments to function `printf'
[Warning] D:\lili\C-Free\Temp\未命名5.c:687: warning: passing arg 1 of `printf' from incompatible pointer type
[Warning] D:\lili\C-Free\Temp\未命名5.c:714: warning: passing arg 1 of `printf' from incompatible pointer type
[Warning] D:\lili\C-Free\Temp\未命名5.c:717: warning: passing arg 1 of `printf' from incompatible pointer type
[Warning] D:\lili\C-Free\Temp\未命名5.c:718: warning: passing arg 1 of `printf' from incompatible pointer type
[Warning] D:\lili\C-Free\Temp\未命名5.c:719: warning: passing arg 1 of `printf' from incompatible pointer type
[Warning] D:\lili\C-Free\Temp\未命名5.c:720: warning: passing arg 1 of `printf' from incompatible pointer type
[Warning] D:\lili\C-Free\Temp\未命名5.c:721: warning: passing arg 1 of `printf' from incompatible pointer type
[Warning] D:\lili\C-Free\Temp\未命名5.c:722: warning: passing arg 1 of `printf' from incompatible pointer type
[Warning] D:\lili\C-Free\Temp\未命名5.c:723: warning: passing arg 1 of `printf' from incompatible pointer type
[Warning] D:\lili\C-Free\Temp\未命名5.c:724: warning: passing arg 1 of `printf' from incompatible pointer type
[Warning] D:\lili\C-Free\Temp\未命名5.c:725: warning: passing arg 1 of `printf' from incompatible pointer type
[Warning] D:\lili\C-Free\Temp\未命名5.c:726: warning: passing arg 1 of `printf' from incompatible pointer type
[Warning] D:\lili\C-Free\Temp\未命名5.c:727: warning: passing arg 1 of `printf' from incompatible pointer type
[Warning] D:\lili\C-Free\Temp\未命名5.c:728: warning: passing arg 1 of `printf' from incompatible pointer type
[Warning] D:\lili\C-Free\Temp\未命名5.c:729: warning: passing arg 1 of `printf' from incompatible pointer type
[Warning] D:\lili\C-Free\Temp\未命名5.c:730: warning: passing arg 1 of `printf' from incompatible pointer type
[Warning] D:\lili\C-Free\Temp\未命名5.c:731: warning: passing arg 1 of `printf' from incompatible pointer type
[Warning] D:\lili\C-Free\Temp\未命名5.c:732: warning: passing arg 1 of `printf' from incompatible pointer type
[Warning] D:\lili\C-Free\Temp\未命名5.c:733: warning: passing arg 1 of `printf' from incompatible pointer type
[Warning] D:\lili\C-Free\Temp\未命名5.c:734: warning: passing arg 1 of `printf' from incompatible pointer type
[Warning] D:\lili\C-Free\Temp\未命名5.c:735: warning: passing arg 1 of `printf' from incompatible pointer type
[Warning] D:\lili\C-Free\Temp\未命名5.c:736: warning: passing arg 1 of `printf' from incompatible pointer type
[Warning] D:\lili\C-Free\Temp\未命名5.c:737: warning: passing arg 1 of `printf' from incompatible pointer type
[Warning] D:\lili\C-Free\Temp\未命名5.c:738: warning: passing arg 1 of `printf' from incompatible pointer type
[Warning] D:\lili\C-Free\Temp\未命名5.c:739: warning: passing arg 1 of `printf' from incompatible pointer type
[Warning] D:\lili\C-Free\Temp\未命名5.c:741: warning: passing arg 1 of `printf' from incompatible pointer type
[Warning] D:\lili\C-Free\Temp\未命名5.c:744: warning: passing arg 1 of `printf' from incompatible pointer type
[Warning] D:\lili\C-Free\Temp\未命名5.c:764: warning: passing arg 1 of `printf' from incompatible pointer type
[Warning] D:\lili\C-Free\Temp\未命名5.c:767: warning: passing arg 1 of `printf' from incompatible pointer type

构建中止 未命名5: 14 个错误, 67 个警告


出现这种情况是因为大部分的C初学者都知道C(准确的说是C89)有32个关键字, 却不知道C还有保留字一说. 比如经常遇到的NULL,printf,scanf.....等等.
关键字是纯C情况下用的, 也就是说仅仅在支持纯C的编译器下不能用关键字. 但是保留字是C89规定的, 这些保留字对于程序员来说,一样不能随便修改和使用.  
比如说printf,如果你调用stdio.h文件,你就不能随便定义printf这个词了(而你的程序中正好违反了这一点).  大部分的编译器都不允许你随便用这几个字的, 平时应该注意一下这些库函数的名字,尽量不用和它们一样的名字, 如果实在没法, 可以不用包含那个函数的头文件.  
第586行
程序代码:
 
           .......
            break;
        case 3:
            return head;
            break;
              



       }
   }
        return head;
        

}
int printf(struct node *head)          //对printf重新定义.
{
    

    struct node *p;
    int i,s1,s;
    char *name;
    char string[20];
    name=string;
    p=head->next;
    if(p==NULL)
    ......

有的编译器允许用户在程序中可以不写"include <stdio.h>"或者"include 'stdio.h'",但编译器在编译的时候会自动添加这一句以便调用这个文件.  

编译器表示对你的程序很傻眼.  修改一下再试着编译吧.

另外,你的帖子没有标题, 坛子里的朋友很难打开你的帖子, 即使想帮你,都很费劲.

[ 本帖最后由 vvvcuu 于 2014-6-9 19:13 编辑 ]

代码测试环境:  WinXP+C-Free5.0.
2014-06-09 18:59
embed_xuel
Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19
等 级:贵宾
威 望:58
帖 子:3845
专家分:11385
注 册:2011-9-13
收藏
得分:2 
NULL,printf,scanf.....  
这些都不叫保留字

总有那身价贱的人给作业贴回复完整的代码
2014-06-09 19:14
lrx2014
Rank: 1
等 级:新手上路
帖 子:39
专家分:0
注 册:2014-4-11
收藏
得分:0 
我能跑出來,一開始不懂得什麼意思,現在大概知道了。
2014-06-09 20:55
vvvcuu
Rank: 9Rank: 9Rank: 9
等 级:贵宾
威 望:12
帖 子:353
专家分:1253
注 册:2014-4-22
收藏
得分:0 
回复 3 楼 embed_xuel
其实我也不知道该用什么词来表达更准确一些.

只能说那些词在标准C中并不代表什么,因为标准C中没有这些内容.  但在C89,C99等中, 这些词确实是被定义了的,程序员或者说C用户是不能随意动用这些词的.  为了区别开来,用保留字这个词也未尝不可.

代码测试环境:  WinXP+C-Free5.0.
2014-06-09 21:55
embed_xuel
Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19
等 级:贵宾
威 望:58
帖 子:3845
专家分:11385
注 册:2011-9-13
收藏
得分:0 
回复 5 楼 vvvcuu
既然这样我就没啥可说了

总有那身价贱的人给作业贴回复完整的代码
2014-06-09 23:18
TonyDeng
Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20
等 级:贵宾
威 望:304
帖 子:25859
专家分:48889
注 册:2011-6-22
收藏
得分:2 
以下是引用vvvcuu在2014-6-9 21:55:08的发言:

其实我也不知道该用什么词来表达更准确一些.
 
只能说那些词在标准C中并不代表什么,因为标准C中没有这些内容.  但在C89,C99等中, 这些词确实是被定义了的,程序员或者说C用户是不能随意动用这些词的.  为了区别开来,用保留字这个词也未尝不可.

在解释这个问题之前,你有想过为什么在没引入stdio.h之前,编译器说printf()函数不存在,是什么原因呢?

授人以渔,不授人以鱼。
2014-06-10 11:57
xiaozi2013
Rank: 13Rank: 13Rank: 13Rank: 13
来 自:四川成都
等 级:蒙面侠
威 望:6
帖 子:830
专家分:4331
注 册:2013-12-13
收藏
得分:2 
长甩甩哒

--整天敲那些破代码能找着媳妇儿吗。。。---
2014-06-10 20:43
vvvcuu
Rank: 9Rank: 9Rank: 9
等 级:贵宾
威 望:12
帖 子:353
专家分:1253
注 册:2014-4-22
收藏
得分:0 
回复 7 楼 TonyDeng
C不允许使用未定义的函数.   printf()正是在stdio.h中定义的.

下面的话可能有点孔乙己或者说钻牛角尖了.

谭浩强教材<<C程序设计(第二版)>>P70最后一句"考虑到printf和scanf函数使用频繁,系统允许在使用这两个函数时可不加#include命令."

虽然我不知道它说的系统是什么系统, 但目前来看, turbo C2.0确实可以这样,而且不报错,不警告.  dev c++能够编译通过,但会报个错误: [Error] 'printf' was not declared in this scope.    其它编译器下不知道效果如何.

这句话固然不严谨, 不利于对C的学习,但我们是否可以这样理解,  因为这两个函数的常用性, 为了使你写的程序易读, 易移植,  请不要随便的自己重写这两个函数,  请不要随意重定义这两个函数.  

尽管我们可以自己重写所有的函数, 但是不论初学者还是专业的C程序员,恐怕很少有人去重写这些函数吧.  

尽管这些常用的函数名并不属于C规定的关键字,  但已经成为事实上的关键字.

现实中, 对这些函数的重写估计只有在面试的时候测试基本功才会用到吧.

代码测试环境:  WinXP+C-Free5.0.
2014-06-10 21:44
TonyDeng
Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20
等 级:贵宾
威 望:304
帖 子:25859
专家分:48889
注 册:2011-6-22
收藏
得分:0 
回复 9 楼 vvvcuu
不是的。引入stdio.h表示使用了别人写好的一个库,该库中包含printf()函数,所以这个时候就不能再定义一个同名的printf()函数(在C++中可以,只要函数的参数不完全一样即可,那叫函数重载,C是没有的)。标准库,或其他的什么扩展库,其实都只是存储于磁盘中,程序员用不用是自由的,当他决定不用的时候,那些函数就是不存在的,他当然可以自己写一个,也可以与那些已存在但没使用的函数同名。所以,诸如printf()这种,不是保留字,也不是语言标准,只不过是用得最普遍的现成函数而已,这种现成函数被标准委员会纳入为标准库,但不是标准。

Turbo C/Borland C的确是在程序员没明确写出include指令的时候引入了stdio.h,那其实不是语言行为,而是编译器行为,这些编译器在编译时自动加插了#include该头的指令,也就是说,它自作聪明地替你补上了该指令,而不用你写。但并非所有编译器都这样做,毕竟有利也有弊,自动是自动了,但当程序员确实想不要的时候,就没办法了,这叫请神容易送神难——其实手动敲入这一条指令并不费事,本来不用如此代劳,别的不这样做的编译器也是这么考虑的。

授人以渔,不授人以鱼。
2014-06-11 11:21
快速回复:
数据加载中...
 
   



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

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