Monday, May 16, 2016

Check Two Strings Length Equality By Using Pointers.





#include<stdio.h>
int main(){

    char string1[20],string2[20],*ptr_str1,*ptr_str2;
    int i ;

    printf("Enter First String: ");
    scanf("%s",string1);

    printf("Enter Second String: ");
    scanf("%s",string2);

    ptr_str1 = string1;
    ptr_str2 = string2;

    while(*ptr_str1 == *ptr_str2)
    {

        if ( *ptr_str1 == '\0' || *ptr_str2 == '\0' )
            break;

        ptr_str1++;
        ptr_str2++;

    }

    if( *ptr_str1 == '\0' && *ptr_str2 == '\0' )
        printf("Strings Are Equal.\n");

    else
        printf("Strings Are Not Equal.\n");

        return 0;

}


Share this

0 Comment to "Check Two Strings Length Equality By Using Pointers."

Post a Comment