Hey guys,
What I'm trying to do is a function that gets a certain array of structures and print some of the information on the screen, like the name and id_number. The thing is that some fields in the structure are repeated and my goal is to show only one time.
For instance, there are a lot of owners each one has on id_number, but they can have different cars, and I only want my program to show the name and the id_numbers one time for each owner even if the same owner has a 2 or more cars.
here's my code to better understanding of my question:
typedef struct {
int id_number;
char name[50+1];
char address [50+1];
char car[20];
}OWNER;
typedef struct {
int count;
OWNER owners[24000];
}SEVERAL_OWNERS;
void show_owners(SEVERAL_OWNERS *list) {
SEVERAL_OWNERS *ptr=NULL;
int i, j;
for (ptr=list, i=0; i<list->count; i++) {
for (j=i, j<list->count; j++) {
if(list->owners[i].id_number == ptr->owners[j].id_number)
printf("%d %s\n", list->owners[i].id_number, list->owners[i].name);
break;
}
}
}
let's suppose all the fields of the structure are loaded, and what I'm trying is to compare an id_number, which is unique for a certain owner, and search for any other occurrences on the array of structures. If there's not another occurrence I shall print the id_number and the name of the owner on the screen, if so I should only print the same information one time. The problem with this code is that I'm always printing the id_numbers and the names.
If someone could help me out with this I would be very grateful.
Btw sorry for the messy explanation of my problem, English it's not my 1st language...:$
Cheers!