How to search on char that has been randomly generated in an array of structures.
If char is found the function must return the info[i].num
in array of struct, where info is the array of structures (see code below).
I got error in gcc
warning: comparison between pointer and integer
if(info[j].name == s );
how can I use correct comparison ??
#include <stdio.h>
#include <stdlib.h>
#include<string.h>
#define InfoSize 3
int main(int argc, char *argv[])
{
char arr[20];
struct st
{
char name[20];
int num[5];
};
struct st info[InfoSize] = {{ "some10",6 },{"some50",8},{"some5",4}};
int r = rand() % (50 + 1 - 10) + 10 ;
char s = sprintf( arr, "some%d", r );
for(int j=0;j<3;j++){
if(info[j].name == s )
printf("found %s and it's num =%d",info[j].name,info[j].num);
}