Pages

Tuesday 19 February 2019

Program to illustrate string manipulation functions - strlen() , strcpy() , strcmp() ,strcat()

/*Program to Illustration of string manipulation functions   - strlen() , strcpy() , strcmp() , strcat() */
#include<stdio.h>
#include<string.h>
void main()
{
   char s1[50],s2[50],s3[50];
   char substr[50];
   int cmp,position,n,i,j,l,m;
   printf("\n Enter string1:");
   scanf("%s",s1);
   l=strlen(s1);
   printf("Lenght of the string  s1 is %d",l); 
   printf("\n\n Enter string2:");
   scanf("%s",s2);
   m=strlen(s2);
   printf("Lenght of the string s2 is %d",m);
   strcpy(s3,s1);
   printf("\n\nAfter copying S1 into S3,the string S3 is %s",s3);
   printf("\nString S1\t:%s",s1);
   printf("\nString S2\t:%s",s2);
   printf("\nString S3\t:%s",s3);
   cmp=strcmp(s1,s2);
   if(cmp==0)
     printf("\nStrings S1 and S2 are equal.");
   else
     printf("\nStrings S1 and S2 are unequal.");
   strcat(s1,s2);
   printf("\n\nAfter concatanation,the string S1 is %s",s1);
   printf("\n\nEnter the position and number of characters you wnat to extract from the concatenated string:");
   scanf("%d %d",&position,&n);
   for(i=position-1, j=0 ; j<n ; i++, j++)
    {
    substr[j]=s1[i];
    }
   substr[j]='\0';
   printf("\nThe substring extracted from string S1 is %s",substr);
  
}

output:


No comments:

Post a Comment

Programs in turboc3 : Files

File Handling in C File Handling concept in C language is used for store a data permanently in computer. Using this concept we can store our...