m0_68378131 2022-04-08 08:03 采纳率: 100%
浏览 42
已结题

请问,为什么这个代码只能输入,没有输出

请问,为什么这个代码只能输入,没有输出
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <malloc.h>
struct list{
int num;
char name[30];
double salary;
struct list*next;
};
struct list *create()
{
struct list *head;
struct list p;
struct list tail;
int n=0;
int num;
char name[30];
double salary;
//tail=p=(struct list
)malloc(sizeof(struct list));
scanf("%d",&num);
while(num!=0){
n++;
scanf("%s\t%ld",name,&salary);
p=(struct list
)malloc(sizeof(struct list));
p->num=num;p->salary=salary;strcpy(p->name,name);
p->next=NULL;
if(n==1)
head=p;
else
tail->next=p;
tail=p;

     scanf("%d",&num);       
}
return head;

}
int main()
{

printf("请输入职工信息:");
struct list *head=create();
void max_list(struct list *head);
max_list(head);
return 0;

}
void max_list(struct list *head)
{
struct list *z,q;
q=z=(struct list
)malloc(sizeof(struct list));
z=head;

for(q=head;q->next!=NULL;q=q->next)
{
    if(q->salary>z->salary)
    {
        z=q;
    }
    z->next=NULL;
}
printf("最高基本工资的员工信息:&s &ld",z->name,z->salary);
//return head;

}

  • 写回答

4条回答 默认 最新

  • qzjhjxj 2022-04-08 13:04
    关注

    修改如下,供参考:

    #include <stdio.h>
    #include <stdlib.h>
    #include <string.h>
    #include <malloc.h>
    struct list {
        int    num;
        char   name[30];
        double salary;
        struct list* next;
    };
    struct list* create()
    {
        struct list* head;
        struct list* p;
        struct list* tail;
        int n = 0;
        int num;
        char name[30];
        double salary;
        //tail=p=(struct list)malloc(sizeof(struct list));
        scanf("%d", &num);
        while (num != 0) {
            n++;
            scanf("%s %ld", name, &salary);  //scanf("%s\t%ld", name, &salary); 修改
            p = (struct list*)malloc(sizeof(struct list));
            p->num = num; 
            p->salary = salary; 
            strcpy(p->name, name);
            p->next = NULL;
            if (n == 1)
                head = p;
            else
                tail->next = p;
            tail = p;
            scanf("%d", &num);
        }
        return head;
    }
    int main()
    {
        printf("请输入职工信息:");
        struct list* head = create();
        void max_list(struct list* head);
        max_list(head);
        return 0;
    }
    void max_list(struct list* head)
    {
        struct list* z,* q;
        //q = z = (struct list*)malloc(sizeof(struct list)); //修改
        z = head;
    
        for (q = head; q != NULL; q = q->next) 
            //for (q = head; q->next != NULL; q = q->next)修改
        {
            if (q->salary > z->salary)
            {
                z = q;
            }
            //z->next = NULL;  修改
        }
        printf("最高基本工资的员工信息:%s %ld", z->name, z->salary);
        //printf("最高基本工资的员工信息:&s &ld",z->name,z->salary); 修改
        //return head;
    }
    
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)

报告相同问题?

问题事件

  • 系统已结题 4月16日
  • 已采纳回答 4月8日
  • 创建了问题 4月8日

悬赏问题

  • ¥15 怎样才能让鼠标沿着线条的中心线轨迹移动
  • ¥60 用visual studio编写程序,利用间接平差求解水准网
  • ¥15 Llama如何调用shell或者Python
  • ¥20 谁能帮我挨个解读这个php语言编的代码什么意思?
  • ¥15 win10权限管理,限制普通用户使用删除功能
  • ¥15 minnio内存占用过大,内存没被回收(Windows环境)
  • ¥65 抖音咸鱼付款链接转码支付宝
  • ¥15 ubuntu22.04上安装ursim-3.15.8.106339遇到的问题
  • ¥15 blast算法(相关搜索:数据库)
  • ¥15 请问有人会紧聚焦相关的matlab知识嘛?