C program to Compare two String using Pointer

C program to Compare two String using Pointer . compiled in DEV C++

 

#include<stdio.h>
#include<string.h>
#include<conio.h>
int compare_string(char * , char *);
main()
{
        char a[30],b[30];
        int result;
        printf("\n Program to Compare Two String Using Pointer\n");
        printf("\n--------------------------------------------------------\n\n\n");
        printf("First Text : ");
        gets(a);
        printf("\nSecond Text : ");
        gets(b);
        result=compare_string(a,b);
        if(result==1)
        printf("\nString are Same");
        else
        printf("\nString are not Same");
        getch();
        }

   int compare_string(char *first , char *second)
     {
       while(*first!='\0')
       {
           if(*first==*second)
              {
                  first++;
                  second++;
               }
                else
              {
               return 0;
              }

       }

       return 1;

     }

 

 Output

compare

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s