Skip to main content

Posts

Showing posts with the label c programs on string

Sample C Program To Sort A Given Number Of Strings.

C Program To Sort A Given Number Of Strings. #include <stdio.h> #include <conio.h> #include <string.h> main() { char str[4][10]; int i; clrscr(); for( i = 0; i < 4; i++ )   {      printf(“ \n Enter name %d: ”, i+1 );      scanf(“ %s ”, str[i] );   } printf(“\n Original Order \n”); for(i = 0; i < 4; i++ )      printf(“ %s\t ”, str[i] ); for(i = 0; i < 4; i++ )   {     for(j = i + 1; j < 4; j++ )        if( strcmp(str[i], str[j]) > 0 )          {             strcpy( temp, str[i] );             strcpy( temp, str[i], str[j] );             strcpy( str[j], temp );          }   } printf(“\n Sorted Order \n”); for( i = 0; i < 4; i++ )     printf(“ %s\t ”, str[i]); getch(); ...