0

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????

3
Contributors
5
Replies
7
Views
5 Years
Discussion Span
Last Post by zeroliken
0

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

0

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");
}
0

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]);
}
}
0

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

Edited by zeroliken

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.