3/20/2016

C Program To Compare Two String Using Pointer

Problem:- 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 c++ program to compare two strings without using strcmp or oops concepts with explanation and example or string compare in c without using a library function

Check This:- Hacker rank solution for Strings, Classes, STL, Inheritance in C++.


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.

Also Check:- Geeksforgeeks solution for School, Basic, Easy, Medium, Hard in C++.

Extreme Recommended:- If this post is beneficial for you and you want Updates for New post then please like our Facebook Page or Join our Facebook Group and Google plus Community for up-to-date for a new post or if you have any Query you can ask there with lots of coders also suggest to your Friends to join and like our page, so we can help our community, and don't forget to Subscribe. Enter your Email and click to subscribe.


Solution:-

#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:-

C Program To Compare Two String Using Pointer



You May Also Like


1. C++ Program To Check An Array Is Armstrong Or Not

2. C++ Program To Sort An Array Using BUBBLE SORT TECHNIQUE

3. C++ Program To Sort An Array Using SELECTION SORT TECHNIQUE

4. C++ Program To Find Cube Of Any Number Using Functions

5. C++ Program To Perform All Arithmetic Operations Using Functions

6. C++ Program To Find GCD (Greatest Common Divisor ) Using Functions

7. C++ Program For Swapping Two Number In Function Using Pointer

8. C++ Program To Print Address Of Pointer Of An Array Using Pointer

9. C++ Program For Store Employee Information And Display Using Structure

10. C++ Program For Employee Information Using Nested Structure


No comments:

Post a Comment