Problem 1
To store a string of length 2, you need a char
array of size 3. Use:
char array[n][3];
Problem 2
You are using &tmp
in the call to scanf
. That is wrong on two accounts.
The type is not appropriate. Type of &tmp
is char**
. scanf
needs a char*
with the %s
format specifier.
&tmp
cannot hold a string.
You could use
scanf("%s", tmp);
That will be OK from type point of view but it won't ok from run time point of view since tmp
does not point to anything valid.
You can do away with tmp
altogether and use:
scanf("%s", array[i]);
That entire block of code can be:
int n;
scanf("%d", &n);
char array[n][3];
for (int i = 0; i < n; i++)
{
// Make sure you don't read more than 2 chars.
scanf("%2s", array[i]);
}