C Chapters

C program to demostrate the string functions.

String Handling Funtions - Character Arrays and Strings
#include <stdio.h>
#include <string.h>

int main()
{
     char s1[30] = "programming-code.com";
     char s2[30] = "www.programming-code.com";

    if (strcmp(s1, s2) ==0) /* Compare two strings */
    {
       printf("string 1 and string 2 are equal \n");
    }
    else
    {
       printf("string 1 and 2 are different \n");
    }
    
    strcpy(s1,s2); /* Copy string function */
    printf("s2 copied in s1 = %s",s1);
    
    return 0;
}

Output :
string 1 and 2 are different
s2 copied in s1 = www.programming-code.com

Leave a comment
Recent Comments
No Comments