two-dimensional array and function

Hi,

Actually I'm using C, not C++ but i think the codes are just about the same that's why i joined this forum. Hopefully someone could help me.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#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?

Thanks.
At line 16 you are passing custName[intCount] which is a char[50] but the function has a char[][50] argument
Hi Bazzy,

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.

Thanks very much. :)
Topic archived. No new replies allowed.