| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 2871 人关注过本帖
标题:帮忙解释下面程序里res什么意思
只看楼主 加入收藏
cx10701
Rank: 1
来 自:武汉
等 级:新手上路
帖 子:1
专家分:0
注 册:2010-10-31
结帖率:0
收藏
已结贴  问题点数:20 回复次数:2 
帮忙解释下面程序里res什么意思
#include<stdio.h>
#include<string.h>
#include<ctype.h>

typedef struct resisdent
{
    long num;                       // 编号
    char adress[50];                // 用户地址
    char name[50];                  // 户名
    long last_num;                  // 上次读数
    long now_num;                   // 抄表读数
    long cost_remain;               // 电费余额
    struct resisdent *next;         // 下一个用户
} res;

void main()
{
    // 函数声明
    res *enter(); //就是这里
    res *delete(res *);
    res *alter(res *);
    void display(res *);
    void search(res *);
    res *jiaofei(res *);
    res *chaobiao(res *);
    int menu_select();

    // 变量初始化
    // head 变量保存链表头指针
    res *head=NULL;
    res *p1,*p2,*p3;
    int i,j,k;

    for(;;)
    {
        switch(menu_select())
        {
            case 1: head=enter();break;
            case 2: head=delete(head);break;
            case 3: head=alter(head);break;
            case 4: display(head);break;
            case 5: search(head);break;
            case 6: head=jiaofei(head);break;
            case 7: head=chaobiao(head);break;
            case 8: exit(0);
        }
    }
}
// 菜单选项
int menu_select()
{
    int ch;
    printf("***************Welcome to the eletronic system**********************************\n");
    printf("\t1.Enter the static of the resisdent.\n");
    printf("\t2.Delete the static of the resisdent.\n");
    printf("\t3.Alter the static of the resisdent.\n");
    printf("\t4.Display the static of the resisdent.\n");
    printf("\t5.Search the static of the resisdent.\n");
    printf("\t6.Hand up the cost.\n");
    printf("\t7.Updata the reader.\n");
    printf("\t8.Quit.\n");
    printf("********************************************************************************\n");
    do
    {
        printf("Make a chioce(1--8):");
        scanf("%d",&ch);
    } while(ch<1 || ch>8);
    return(ch);
}
// 录入数据,当编号为 0 则退出
res *enter()
{
    res *head = NULL;
    res *p1 = NULL;
    res *p2 = NULL;
    res *p3 = NULL;
    int n=0;
    p1=p2=(res *) malloc (sizeof(res)); //还有这里

  printf("Enter the static of the resisdent:\n");
    printf("num:");
    scanf("%ld",&p1->num);

    if(p1->num==0)
        goto end;

    printf("adress:");
    scanf("%s",p1->adress);
    printf("name:");
    scanf("%s",p1->name);
    printf("The number of last time:");
    scanf("%ld",&p1->last_num);
    printf("The number of now:");
    scanf("%ld",&p1->now_num);
    printf("The cost remain:");
    scanf("%ld",&p1->cost_remain);

    while(p1->num!=0)
    {
        n=n+1;

        // 如果计数为1,则置表头为p1,
        // 否则将新建节点添加至上一节点(此时为p2)尾部
        if(n==1)
            head=p1;
        else
            p2->next=p1;

        p2=p1;
        p1=(res *) malloc (sizeof(res));
        printf("num:");
        scanf("%ld",&p1->num);

        if(p1->num==0)
            goto end;

        printf("adress:");
        scanf("%s",p1->adress);
        printf("name:");
        scanf("%s",p1->name);
        printf("The number of last time:");
        scanf("%ld",&p1->last_num);
        printf("The number of now:");
        scanf("%ld",&p1->now_num);
        printf("The cost remain:");
        scanf("%ld",&p1->cost_remain);
    }

    end:
        p2->next=NULL;
        return(head);
}
// 根据输入的编号删除对应项
// 返回更新后的链表表头指针
res *delete(res *head)
{
    res *p1,*p2;
    long num;

    if(head==NULL)
        printf("The list is empty.!\n");
    else
    {
        printf("Enter the num to delete:");
        scanf("%ld",&num);
        p1=p2=head;

        while(p1->num!=num && p1->next!=NULL)
        {
            p2=p1;
            p1=p1->next;
        }

        if(num==p1->num)
        {
            if(head==p1)
                head=p1->next;
        else
            p2->next=p1->next;
        }
        else
            printf("Not found!\n");

    }
    return(head);
}


// 输入编号,修改对应项
// 返回表头指针
res *alter(res *head)
{
    res *p1,*p2;
    long num;

    if(head==NULL)
        printf("Null list.\n");
    else
    {
        printf("Enter the num to alter:");
        scanf("%ld",&num);
        p1=head;

        while(p1->num!=num &&p1->next!=NULL)
            p1=p1->next;
        if(num==p1->num)
        {
            printf("new num:");
            scanf("%ld",&p1->num);
            printf("new adress:");
            scanf("%s",p1->adress);
            printf("new name:");
            scanf("%s",p1->name);
            printf("The number of last time:");
            scanf("%ld",&p1->last_num);
            printf("The number of now:");
            scanf("%ld",&p1->now_num);
            printf("The cost remain:");
            scanf("%ld",&p1->cost_remain);
        }
        else
        printf("Not found!\n");
    }
    return(head);
}


// 显示表中所有项目
void display(res *head)
{
    res *p1,*p2;
    p1=p2=head;
    printf("********************************************************************************\n");
    printf("\tNUM\tADRESS\tNAME\tNUMBER_LAST\tNUMBER_NOW\tCOST_REMAIN\n");

    while(p1!=NULL)
    {
        printf("\t%-3ld\t%-6s\t%-4s\t%-11ld\t%-10ld\t%-5ld\n",p1->num,p1->adress,
        p1->name,p1->last_num,p1->now_num,p1->cost_remain);
        p1=p1->next;
    }
    printf("********************************************************************************\n");
}

// 查询
void search(res *head)
{
    res *p1,*p2;
    char ser[50];
    int n;
    printf("1.search by adress.\n");
    printf("2.search by name.\n");
    printf("choose 1 || 2:\n");
    scanf("%d",&n);
    if(head==NULL)
        printf("NULL list.\n");
    switch(n)
    {
        case 1:
            printf("input the adress:");
            scanf("%s",ser);
            p1=p2=head;
            while(strcmp(p1->adress,ser)!=0 &&p1->next!=NULL)
            p1=p1->next;
            if(strcmp(p1->adress,ser)==0)
            {
                printf("\tNUM\tADRESS\tNAME\tLAST_NUM\tNOW_NUM\tCOST_REMAIN\n");
                printf("\t%-3ld\t%-6s\t%-4s\t%-11ld\t%-10ld\t%-5ld\n",p1->num,p1->adress,p1->name,
                p1->last_num,p1->now_num,p1->cost_remain);
            }
            else
                printf("Not found!\n");break;
        case 2:
        {
            printf("input the name:");
            scanf("%s",ser);
            p1=p2=head;
            while(strcmp(p1->name,ser)!=0 && p1->next!=NULL)
            p1=p1->next;
            if(strcmp(p1->name,ser)==0)
            {
                printf("\tNUM\tADRESS\tNAME\tLAST_NUM\tNOW_NUM\tCOST_REMAIN\n");
                printf("\t%-3ld\t%-6s\t%-4s\t%-11ld\t%-10ld\t%-5ld\n",p1->num,p1->adress,p1->name,
                p1->last_num,p1->now_num,p1->cost_remain);
            }
            else
                printf("Not found!\n");break;
        }
        default:break;
    }
}
res *jiaofei(res *head)
{
    res *p1,*p2;
    char adress[50];
    long cost;
    printf("input the adress:");
    scanf("%s",adress);

    if(head==NULL)
        printf("NULL list!\n");
    else
    {
        p1=head;
        while(strcmp(p1->adress,adress)!=0 && p1->next!=NULL)
            p1=p1->next;
        if(strcmp(p1->adress,adress)==0)
        {
            printf("input the number of the cost:");
            scanf("%ld",&cost);
            p1->cost_remain+=cost;
        }
        else
            printf("Not found!\n");
    }
    return(head);
}

res *chaobiao(res *head)
{
    res *p1,*p2;
    char adress[50];

    if(head==NULL)
        printf("NULL list!\n");
    else
    {
        printf("input the adress:");
        scanf("%s",adress);
        p1=head;

        while(strcmp(p1->adress,adress)!=0 && p1->next!=NULL)
            p1=p1->next;
        if(strcmp(p1->adress,adress)==0)
        {
            p1->last_num=p1->now_num;
            printf("input the num:");
            scanf("%ld",&p1->now_num);
        }
        else
            printf("Not found!\n");
    }
    return(head);
}
搜索更多相关主题的帖子: 解释 res 
2010-10-31 12:20
yu_hua
Rank: 2
等 级:论坛游民
帖 子:222
专家分:95
注 册:2006-8-10
收藏
得分:10 
“res”相当于“struct resisdent”是类型说明,
表示在它右面出现的标识符为 struct resisdent 类型。
2010-10-31 12:25
wujieru
Rank: 10Rank: 10Rank: 10
等 级:青峰侠
威 望:1
帖 子:1108
专家分:1939
注 册:2010-10-9
收藏
得分:10 
typedef struct resisdent
注意这个
2010-10-31 12:26
快速回复:帮忙解释下面程序里res什么意思
数据加载中...
 
   



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

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