Program for sorting of string in c language



Program for sorting of string in c language

#include<stdio.h>
int main(){
  int i,j,n;
  char str[20][20],temp[20];
  puts("Enter the no. of string to be sorted");
  scanf("%d",&n);
  for(i=0;i<=n;i++)
      gets(str[i]);
  for(i=0;i<=n;i++)
      for(j=i+1;j<=n;j++){
           if(strcmp(str[i],str[j])>0){
               strcpy(temp,str[i]);
              strcpy(str[i],str[j]);
              strcpy(str[j],temp);
           }
      }
  printf("The sorted string\n");
  for(i=0;i<=n;i++)
      puts(str[i]);
  return 0;
}

String concatenation in c without using string functions

#include<stdio.h>

void stringConcat(char[],char[]);
int main(){

    char str1[100],str2[100];
    int compare;

    printf("Enter first string: ");
    scanf("%s",str1);

    printf("Enter second string: ");
    scanf("%s",str2);

    stringConcat(str1,str2);

    printf("String after concatenation: %s",str1);

    return 0;
}

void stringConcat(char str1[],char str2[]){
    int i=0,j=0;
   
   
    while(str1[i]!='\0'){
         i++;
    }

    while(str2[j]!='\0'){
         str1[i] = str2[j];   
         i++;
         j++;
    }

    str1[i] = '\0';
}
 
Share on Google Plus

About Unknown

Hello, My name is Mou, I am from Dhaka, Bangladesh and who is trying keep her hand at blogging. I enjoy writing, anything from how to- pieces to endure to just anything at all. My blog will go into detail about all of article. Long time I work with adsense and blogging about 10 years. Doing some SEO work and like that. Please stay close for track down your article for your task and assignment. Feel free to contact with me at moujuena.mou@gmail.com if need. Thanks for visiting.
    Blogger Comment
    Facebook Comment

0 comments:

Post a Comment