You are here:

C/rearrange string

Advertisement


salbert jotj wrote at 2009-11-07 16:41:03
Prince M. Premnath ,

I saw from question, we need to repeat insert string until receive string "END".How to put this condition in loop program.

thank in advance,


Prince M. Premnath wrote at 2009-12-10 11:09:32
Please try with the code given below



#include<stdio.h>

#include<conio.h>

#include<string.h>

char Names[30][20]; /* Can store a maxmium of 30 names of size 20 */

void main()

{

   char Temp[20];

   int i,j;

   int n = 0;

   printf("Enter \'END\' To terminate input..\n");

   do{

       printf("Enter String [%d] :",n);

       gets(Names[n++]);

   }while(strcmp(Names[n-1],"END")!=0);

   n--;    /* Ignore the recently Entered "END" */

  

   for( i = 0; i<n ; i++)

       for(j=0; j< n-1; j++)

         if( strncmp(Names[j], Names[j+1],1) > 0 )

         {

         strcpy(Temp,Names[j]);

         strcpy(Names[j],Names[j+1]);

         strcpy(Names[j+1],Temp);

         }



   for( i = 0 ; i< n ; i++)

       puts(Names[i]);

   getch();

}  


C

All Answers


Answers by Expert:


Ask Experts

Volunteer


Prince M. Premnath

Expertise


I'm sure that I can solve any doubts in Turbo C ,Graphics Programing ,Mouse, Hardware Programming ,File System ,Interrupts, BIOS handling , TSR Programming , General Concepts in C Language, handling inline Assembly statements

Experience

Research over 6+ Years

Organizations
CG-VAK Softwares and Exports Limited

Education/Credentials
Masters in Computer Applications

©2012 About.com, a part of The New York Times Company. All rights reserved.