#include <stdio.h>
fInsertCust(char[][50], int);
main()
{
int intCount=0, i;
char custName[10][50];
do
{
printf("\n---------------------------------------------");
printf("\nSelect an option\n 1 - Insert customer:\n 0 - Quit\n");
scanf("%d", &i);
if (i==1)
{
fInsertCust(custName[intCount], intCount);
intCount++;
}
}while (i!=0);
for (i=0; i<intCount; i++) /*displays all customers upon quiting*/
{
printf("\nCustomer %d: %s", i+1, custName[i]);
}
}
fInsertCust(char custName[][50], int intCount)
{
fflush(stdin);
printf("Customer %d, name: ", intCount+1);
gets(custName[intCount]);
printf("Welcome %s.", custName[intCount]);
}
The code above will get customer names. But i dont understand why it will just save the first input, third, fifth.. and so on and not the second input, fourth, sixth... Any idea?
You're right. I just changed the function variable to custName[] and that fixed the problem. The output from line 32 is still not right but that doesnt matter cause i dont need the output from that line.