Q:

C Program To Compare Two String Using Pointer

belongs to collection: String in C Programs

0
c program to compare two strings without using strcmp using pointers or c program to compare two strings without using a library function or write a program using a pointer to concat two strings or c program to compare two integer arrays using pointers or write a FoxPro command to add two numbers or  two strings without using strcmp or oops concepts with explanation and example or string compare in c without using a library function
 

Explanation:- 
In this problem, we are comparing a two string using pointers for comparing a two sting we are not using a strcmp function we are comparing with the help of pointer.
First take a input through from user first ake a first string and take a second string and assign both string in two pointer type variable separately, after that run a while loop and put the condition while string1 and string2 is same and also both string not equal null till increase the both string by one character and repeat the process again and again. If the first string is same to a second string then print the message "Both Strings Is Same" if not then print "Both Strings Is Not Same" on screen.

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

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

    char string1[50],string2[50],*str1,*str2;
    int i,equal = 0;

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

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

    str1 = string1;
    str2 = string2;

    while(*str1 == *str2)
    {

        if ( *str1 == '\0' || *str2 == '\0' )
            break;

        str1++;
        str2++;

    }

    if( *str1 == '\0' && *str2 == '\0' )
        printf("\n\nBoth Strings Are Equal.");

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

}

 

Output:

Enter The First String :programming

Enter The Second String:programming

Both Strings Are Equal

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

<< C Program For Reverse a String Using Pointers...