/******************************************************************************
Welcome to GDB Online.
GDB online is an online compiler and debugger tool for C, C++, Python.
Code, Compile, Run and Debug online from anywhere in world.
*******************************************************************************/
#include <stdio.h>
struct foo1 {
int a;
int b;
char *name;
};
struct foo2 {
char c;
double d;
char *name;
};
struct foo1 *foo1_by_name(char const *name, struct foo1 *array, size_t size) {
for(size_t i = 0; i < size; ++i)
if(!memcmp(name, array[i].name))
return &array[i];
return NULL;
}
struct foo2 *foo2_by_name(char const *name, struct foo2 *array, size_t size) {
for(size_t i = 0; i < size; ++i)
if(!memcmp(name, array[i].name))
return &array[i];
return NULL;
}
int main()
{
struct foo1 a1[10] = {0 /* ... */};
struct foo2 a2[10] = {0 /* ... */};
struct foo1 *f1 = foo1_by_name("blah", a1, 10);
struct foo2 *f2 = foo2_by_name("bleh", a2, 10);
return 0;
}