This is because you rewrite the value at each iteration.
You can create an array in main()and pass the array to functions so that the values are stored in different places, instead you always pass the same instance of the structure gets()and, therefore, overwrite the previous value, so the print cycle prints the same data twice .
The following shows how to pass an array
#include <stdio.h>
struct Data
{
char name[50];
};
void readData(struct Data *array);
void showData(struct Data *array);
int main()
{
struct Data array[2];
readData(array);
showData(array);
}
void readData(struct Data *array)
{
int i;
for (i = 0 ; i < 2 ; i++)
{
printf("enter name: ");
fgets(array[i].name, sizeof(array[i].name), stdin);
}
}
void showData(struct Data *array)
{
int i;
for (i = 0 ; i < 2 ; i++)
{
printf("%s", array[i].name);
}
}
, , , , , , , , .