2d array of strings in c
language[0] => "Java";
language[1] => "Python";
language[2] => "C++";
language[3] => "HTML";
language[4] => "SQL";
2d array of strings in c
language[0] => "Java";
language[1] => "Python";
language[2] => "C++";
language[3] => "HTML";
language[4] => "SQL";
2d array of strings in c
// it is valid
char language[ ][10] = {"Java", "Python", "C++", "HTML", "SQL"};
how to arrange a 2d array based on string length in c
1 #include<stdio.h>
2 #include<string.h>
3 void main()
4 {
5 char s[5][10];
6 char t[10];
7 int ele,i,j;
8 ele=(sizeof(s)/sizeof(s[0]));
9 printf("Enter the strings...\n");
10 for(i=0;i<ele;i++)
11 scanf("%s",s[i]);
12 for(i=0;i<ele;i++)
13 printf("%s\n",s[i]);
14
15 for(i=0;i<ele;i++)
16 {
17 for(j=0;j<ele-1-i;j++)
18 {
19 if(strlen(s[j])>strlen(s[j+1]))
20 { strcpy(t,s[j]);
21 strcpy(s[j],s[j+1]);
22 strcpy(s[j+1],t);
23 }
24
25
26 }
27 }
28 printf("After sorting...\n");
29 for(i=0;i<ele;i++)
30 printf("%s ",s[i]);
31 }
~
Copyright © 2021 Codeinu
Forgot your account's password or having trouble logging into your Account? Don't worry, we'll help you to get back your account. Enter your email address and we'll send you a recovery link to reset your password. If you are experiencing problems resetting your password contact us