Search
 
SCRIPT & CODE EXAMPLE
 

C

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...
");
 10 for(i=0;i<ele;i++)
 11 scanf("%s",s[i]);
 12 for(i=0;i<ele;i++)
 13 printf("%s
",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...
");
 29 for(i=0;i<ele;i++)
 30 printf("%s ",s[i]);
 31 }
~        
Comment

PREVIOUS NEXT
Code Example
C :: stddef.h 
C :: c programming exercises 
C :: how to check the word is present in given char array in c 
C :: prime numbers 
C :: c size_t 
C :: enum case statement in c 
C :: how to open form in vb.net 
C :: open a file in from terminal 
C :: oracle trunc 
C :: c program for assignment operator 
C :: size of float in c 
C :: C Syntax of struct 
C :: predefined macros 
C :: c atoi atof 
C :: how to check file pointers in c 
C :: modelform prefill with data 
C :: How to include multiline conditional inside template literal 
C :: C #if, #elif and #else Directive 
C :: C static libraries (creating object files) 
C :: translator program in c 
C :: command line arguments to copy paste in c 
C :: change data type inline in c 
C :: assembly to c code converter 
C :: BEE/URI problem no 1181 solution in C 
C :: lognormal distribution - matlab 
C :: l/O Multiple Values 
C :: C Relationship Between Arrays and Pointers 
C :: declaration of arrays 
C :: how to declare a structure in c 
C :: CODE SOURCE POUR LISTE DOUBLEMENT CHAINEé en c 
ADD CONTENT
Topic
Content
Source link
Name
7+1 =