In this tutorial, we are going to write a C Program to use string handling functions in C Programming with practical program code and step-by-step full complete explanation.

C Program to use string handling functions


C Program to use string handling functions.

 
#include<stdio.h>
#include<conio.h>
#include<string.h>

void main()
{
    char s1[20],s2[20],s3[20];
    int x,l1,l2,l3;

    printf("Enter two string constants\n");
    printf("?");

    scanf("%s %s",s1,s2);

    x=strcmp(s1,s2);

    if(x!=0)
    {

        printf("\nString are not equal");
        strcat(s1,s2);
    }
    else
        printf("\nString are equal");

    strcpy(s3,s1);
    l1=strlen(s1);
    l2=strlen(s2);
    l3=strlen(s3);

    printf("\ns1=%s length=%d characters",s1,l1);
    printf("\ns2=%s length=%d characters",s2,l2);
    printf("\ns3=%s length=%d characters",s3,l3);
}


Output

 
Enter two string constants
? ananda murugan

Strings are not equal
S1=ananda murugan length=13 characters
S2=murugan length=7 characters
S3=ananda murugan length=13 characters

Enter two string constants
? anand anand
String are equal
S1=anand length=5 characters
S2=anand length=5 characters
S3=anand length=5 characters