I am learning 2d arrays in C and im trying to get the user's name in C and store it in a 2d array. I found out that C don't have String
data type and can only accepts string with data type char
.
Now I am successful in getting the name from the user but i can't store the name into the separate 2d array. Here the code i tried:
#include <stdio.h>
#include <cstring>
int main()
{
int to=0,y=1,z=0,end=0;
char *ticketS[100][3];
char name[50];
printf("\nENTER PASSENGER'S NAME: ");
gets(name);
printf("%s",name);
strcpy(ticketS[z][0], name);
printf("%s", ticketS[z][0]);
return 0;
}
My input is: test name
My expected output is:
test name
test name
The actual output is:
test name
I can't seem to find any examples regarding my problem. Any help would be greatly appreciated.