小编teo*_*eoz的帖子

struct和rand()

我有一个结构,其数组为100 int(b)和一个int(a)类型的变量

我有一个函数,检查"a"的值是否在数组中,我已经生成了数组元素和带有随机值的变量.

但它不起作用有人可以帮我解决吗?

#include <stdio.h>
#include <stdlib.h>
#include <time.h>

typedef struct {
    int a;
    int b[100];
} h;

int func(h v){
    int i;

    for (i=0;i<100;i++){
        if(v.b[i]==v.a) 
            return 1;
        else 
            return 0;
    }

}

int main(int argc, char** argv)
{
    h str;
    srand(time(0)); 
    int i;
    for(i=0;0<100;i++){
        str.b[i]=(rand() % 10) + 1;
    }
    str.a=(rand() % 10) + 1;
    str.a=1;

    printf("%d\n",func(str));

    return 0;
}
Run Code Online (Sandbox Code Playgroud)

c

1
推荐指数
1
解决办法
974
查看次数

标签 统计

c ×1