如何使"若"条件的立场在C所有结构项目 [英] How to make "if" condition stand for all struct items in C

查看:94
本文介绍了如何使"若"条件的立场在C所有结构项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道如何让如果状态代表在该节点的所有结构项目。它计算只有1项和退出周期。这里是code。即时试图使该检查在数据库中的项目的到期日期的功能。请忽略保加利亚文。

  LIST * sortPr(LIST * pFirst){    LIST * B = NULL,* P;    LIST * B1,*总线1 = NULL;
    INT yearcur = 1;
    的printf(Vuvedete teku6ta戈迪纳);
    scanf函数(%d个,&安培; yearcur);
    如果(pFirst == NULL)
    {
        的setColor(COL_RED);
        的printf(Списъкътепразен\\ n);
        系统(暂停);
        出口(4);
    }
    为(P = pFirst; P!= NULL; P = P-> pNext)
    {
        如果((yearcur - 对 - > body.year)GT; P-> body.expd)
        {                B =磷;        }        B1 =为newElement(BUS1,B>车身);
        返回B1;
    }
}


解决方案

这是因为你有 B1回报您的循环内。这将第一次迭代后终止,并返回 B1 出来的功能。

  LIST * sortPr(LIST * pFirst){
    LIST * B = NULL,* P;
    LIST * B1,*总线1 = NULL;
    ...
    为(P = pFirst; P!= NULL; P = P-> pNext){
        ...        //这将第一次迭代过程本身返回B1
        返回B1;
    }
}

I want to know how to make that "if" condition stand for all struct items in the node. It counts just 1 items and quits the cycle. Here is the code. Im trying to make a function that checks the expiry date on a item in a database. Please disregard the bulgarian text.

LIST *sortPr(LIST *pFirst) {

    LIST *b = NULL, *p;

    LIST *b1, *bus1 = NULL;
    int yearcur = 1;
    printf("Vuvedete teku6ta godina");
    scanf("%d", &yearcur);
    if (pFirst == NULL)
    {
        setcolor(COL_RED);
        printf("Списъкът е празен\n");
        system("pause");
        exit(4);
    }
    for (p = pFirst; p != NULL; p = p->pNext)
    {
        if ((yearcur - p->body.year) > p->body.expd)
        {

                b = p;



        }

        b1 = newElement(bus1, b->body);
        return b1;
    }
}

解决方案

This is because you have return b1 inside your for loop. This would terminate it after the first iteration, and return b1 out of the function.

LIST *sortPr(LIST *pFirst) {
    LIST *b = NULL, *p;
    LIST *b1, *bus1 = NULL;
    ...
    for (p = pFirst; p != NULL; p = p->pNext) {
        ...

        // This would return b1 during the first iteration itself
        return b1;
    }
}

这篇关于如何使"若"条件的立场在C所有结构项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆