C Programming Articles

Submit Article
Home » Articles » C Programming » BeginnersRSS Feeds

Illustration of string handling functions

Posted By: Jarvia Miller     Category: C Programming     Views: 10567

Illustration of string handling functions.

Code for Illustration of string handling functions in C Programming

   #include    <string.h>                                      
   {   char  s1[20], s2[20], s3[20];                           
       int   x, l1, l2, l3;                                    
       printf("\n\nEnter two string constants \n");            
       scanf("%s %s", s1, s2);                                 
    /* comparing s1 and s2 */
x = strcmp(s1, s2); if(x != 0) { printf("\n\nStrings are not equal \n"); strcat(s1, s2); /* joining s1 and s2 */
} else printf("\n\nStrings are equal \n"); /* copying s1 to s3
strcpy(s3, s1);
/* Finding length of strings */
l1 = strlen(s1); l2 = strlen(s2); l3 = strlen(s3); /* output */
printf("\ns1 = %s\t length = %d characters\n", s1, l1); printf("s2 = %s\t length = %d characters\n", s2, l2); printf("s3 = %s\t length = %d characters\n", s3, l3); } Output Enter two string constants ? New York Strings are not equal s1 = NewYork length = 7 characters s2 = York length = 4 characters s3 = NewYork length = 7 characters Enter two string constants ? London London Strings are equal s1 = London length = 6 characters s2 = London length = 6 characters s3 = London length = 6 characters

Didn't find what you were looking for? Find more on Illustration of string handling functions Or get search suggestion and latest updates.

Jarvia Miller
Jarvia Miller author of Illustration of string handling functions is from Frankfurt, Germany.
View All Articles

Please enter your Comment

  • Comment should be atleast 30 Characters.
  • Please put code inside [Code] your code [/Code].

No Comment Found, Be the First to post comment!