C program to perform string manipulation functions

If you are using any software then below program will not give an error, but if you are using TURBO C then you have to make some changes like: void main() and some function like clrscr() or getch().

#include<stdio.h>
#include<string.h>
main()
{
 int len1,len2;
 char str1[]="IMRT\0";
 char str2[]="INSTITUTE\0";

 printf("First string is %s\n",str1);
 printf("Second string is %s\n\n",str2);

 //Length of the string
 len1=strlen(str1);
 len2=strlen(str2);
 printf("Length of first string is : %d\n",len1);
 printf("Length of second string is : %d\n\n",len2);

 //Comparing both strings
 if(strcmp(str1,str2)==0)
  printf("Both strings are equal\n\n");
 else
  printf("Both strings are not equal\n\n");

 //Concatenation of string
 strcat(str1,str2);
 printf("Concatenation of first & second string is %s\n\n",str1);

 //Reverse the strings
 strrev(str1);
 printf("Reverse of first string is %s\n\n",str1);

 //printing strings
 printf("First string is %s\n",str1);
 printf("Second string is %s\n\n",str2);

 //Copying strings
 strcpy(str2,str1);
 printf("Copied first string to second string %s",str2);
}

OUTPUT:

First string is IMRT
Second string is INSTITUTE

Length of first string is : 4
Length of second string is : 9

Both strings are not equal

Concatenation of first & second string is IMRTINSTITUTE

Reverse of first string is ETUTITSNITRMI

First string is ETUTITSNITRMI
Second string is INSTITUTE

Copied first string to second string ETUTITSNITRMI

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.