Answer to Question #194412 in C for Sankalp

Question #194412

Write a C program to read two strings and explain string library function.

1)strlen()

 2)strcyp()

 3)strcat()

 4) strcmp()


1
Expert's answer
2021-05-17T09:56:13-0400
#include <stdio.h>
#include <string.h>


int main() {
   char str1[20];
   char str2[20];
   printf("Enter string 1: ");
   scanf("%[^\n]",str1);
   fflush(stdin);


   printf("Enter string 2: ");
   scanf("%[^\n]",str2);


   
   //1) strlen() - this function returns the length of the string
   printf("The length of string 1: %d\n",strlen(str1));
   printf("The length of string 2: %d\n",strlen(str2));
   //2) strcyp() - this function allows to copy string from str1 to str 2
   strcpy(str2, str1);
   printf("Copy string from str1 to str2: %s\n",str2);
   //3) strcat() - this function allows concatenate str1 and str2
   strcat(str2, str1);
   printf("Concatenate str1 and str2: %s\n",str2);
   //4) strcmp() - this function allows compare two string str1 and str2.  If the strings are equal, the function returns 0.
   printf("strcmp(str1, str2) = %d\n", strcmp(str1, str2));




   getchar();
   getchar();


   return 0;
}







Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS