C Programming Tutorial

 
 
 
 

Image

#include <stdio.h>
#include <conio.h>
#include <string.h>

void main(){
     int i,n;
     char name[15][20];
     void namesort(char name[15][20], int);
    clrscr();
    printf(\"How many names u want to enter : \");
    scanf(\"%d\",&n);
    printf(\"\\n\\n****Enter Input Data****\\n\");
    for(i=0;i<n;i++){
    flushall();
    printf(\"Enter a name : \");
    gets(name[i]);
    }
    namesort(name,n);
    printf(\"\\n\\n\\n******After Sorting******\\n\");
    for(i=0;i<n;i++)
       printf(\"%s\\n\",name[i]);
    getch();
}

void namesort(char name[15][20],int n){
      int i,j;
      char *temp;
      for(i=0;i<n;i++){
     for(j=0;j<n-1;j++){
        if(strcmp(name[j],name[j+1])>0){
        strcpy(temp,name[j]);
        strcpy(name[j],name[j+1]);
        strcpy(name[j+1],temp);
        }
     }
      }
}

 
 
Didn't find what you were looking for? Find more on Program to sort words