String operation Using functions

 String operation program in c

  1. #include<stdio.h>
  2. int main()
  3. {
  4.      int len;
  5.           char str1[10], str2[10];
  6.      puts("Enter String 1:");
  7.           gets(str1);
  8.      puts("Enter String 2:");
  9.           gets(str2);
  10.      //Function to find length of given string 1.
  11.           len = strlen(str1);
  12.                printf("\nLength of String 1 is %d.\n", len);
  13.      //Function to compare two strings
  14.           if(strcmp(str1,str2)==0)
  15.                      printf("\nString 1 and String 2 are same.\n");
  16.                           else
  17.                                      printf("\nString 1 and String 2 are not same.\n");
  18.      //Function to copy string 1 into string 2
  19.           strcpy(str2,str1); //this will copy str1 into str2
  20.                printf("\nString 2 after execution of strcpy = %s", str2);
  21.      return 0;
  22.      }

Output


Enter String 1:
abc
Enter String 2:
xyz

Length of String 1 is 3.

String 1 and String 2 are not same.

String 2 after execution of strcpy = abc

choose next program from this list

Comments