i have a doubt how can we use string in matrices for examples a[0][0]=rohinn a[0][1]=rithish how to do this????

Recommended Answers

start with something like this:

 char array[3][20]= { "one", "two", "three" };
 printf("%s, %s, %s\n", array[0], array[1], array[2]);

for user input you can use a loop for every index

Jump to Post

If a[0][0] and a[0][1] are both null-terminated strings, then you have to call strcmp() to check of the two strings are the same. The following will produce a two-dimensional array of strings that contain up to 40 characters each.

char a[2][2][40];
strcpy(a[0][0],"Hello");
strcpy(a[0][1],"World");

if( strcmp(a[0][0], a[0][1]) == …
Jump to Post

All 5 Replies

start with something like this:

 char array[3][20]= { "one", "two", "three" };
 printf("%s, %s, %s\n", array[0], array[1], array[2]);

for user input you can use a loop for every index

If a[0][0] and a[0][1] are both null-terminated strings, then you have to call strcmp() to check of the two strings are the same. The following will produce a two-dimensional array of strings that contain up to 40 characters each.

char a[2][2][40];
strcpy(a[0][0],"Hello");
strcpy(a[0][1],"World");

if( strcmp(a[0][0], a[0][1]) == 0)
{
   printf("Both strings are the same\n");
}

no can we use only if we predefine values like this

char array[3][20]= { "one", "two", "three" };
cant we do like this

printf("enter the limit: ");
scanf("%d%d",m,n);
printf("enter the characters: ");
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
{
scanf("%c"a[i][j]);
}
}

yes you can do it like that for single character user input

isn't the code you need similar to the program you posted in this thread. If so if you imply my suggestion of using a 2d array for the variable on the code there then you'll have char array (string) values from user input

Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.20 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.