标题:问题在程序中有显示。。。输入姓名和工资,输出姓名工资,麻烦了
取消只看楼主
c718382171
Rank: 2
等 级:论坛游民
帖 子:32
专家分:41
注 册:2013-12-21
结帖率:83.33%
已结贴  问题点数:5 回复次数:1 
问题在程序中有显示。。。输入姓名和工资,输出姓名工资,麻烦了
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define M 15
struct system{
    char name[M];
    int wage;
    struct system *next;
};
int main (void)
{
    struct system *head=NULL;
    struct system *prev,*current;
    char input [M];
    puts("请输入员工姓名:");
    while(gets(input)!=NULL&&input[0]!='\0')
    {
        current=(struct system *)malloc(sizeof(struct system));
        if(head==NULL)
            head=current;
        else
            prev->next=current;

        current->next=NULL;
        strcpy(current->name,input);
        puts("请输入你的工资:");
        scanf("%d",&current->wage);
        while(getchar()!='\n')
            continue;
        puts("请输入下个员工姓名:");
        prev=current;
    }
    if(head==NULL)
        printf("没有输入数据");
    else
        printf("下面是输出数据\n");
    current=head;
    while(current!=NULL)
    {
        printf("姓名:%s  工资:%d\n",current->name,current->wage);
        current=current->next;
    }
/*这个位置如果添加了一个“current=head;”为什么就不能正常运行了*/
    while(current!=NULL)
    {
        free(current);
        current=current->next;
    }
    printf("ok!");
    return 0;
}
搜索更多相关主题的帖子: current include system 姓名 
2014-01-02 16:48
c718382171
Rank: 2
等 级:论坛游民
帖 子:32
专家分:41
注 册:2013-12-21
得分:0 
不懂
2014-01-02 23:22



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-426032-1-1.html




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

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