struct and rand()
- by teoz
I have a struct with an array of 100 int (b) and a variable of type int (a)
I have a function that checks if the value of "a" is in the array and i have generated the array elements and the variable with random values.
but it doesn't work
can someone help me fix it?
#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;
}