I am trying to pass structures that I have in an array. The code compiles but the programs spews trash when it runs. Does anybody have an suggestions for me to fix this?
Code:
#include <stdio.h>
#include <string.h>
typedef struct {
char name[20];
int number;
} id;
void input (id, int);
void read (id);
int main (void)
{
id array[2];
int index;
for(index = 0 ; index < 2 ; index++)
input(array[index], index);
printf("Here are the two names with their ID:\n\n");
for(index = 0 ; index < 2 ; index++)
read(array[index]);
printf("\n\n");
return(0);
}
void input (id current_struct, int number)
{
printf("\n\nPlease enter name %d: ", number+1);
scanf("%s", current_struct.name);
printf("Please enter %s's id number: ", current_struct.name);
scanf("%d", ¤t_struct.number);
return;
}
void read (id reading_struct)
{
printf("Name:%s \nID:%d",reading_struct.name,reading_struct.number);
return;
}
Thanks!