Your IP : 216.73.216.40


Current Path : /var/www/html/venkat/old/
Upload File :
Current File : /var/www/html/venkat/old/lit2015035_2.c

//Write a program to compare two strings and concatenate & print the first string if not matches. Use pointer variables. Do not use <string.h>.
#include<stdio.h>
int main()
{
  char str1[100],str2[100];
  char *p,*q;
  int flag=1;


  //input strings
  gets(str1);
  gets(str2);
  
  p=str1;
  q=str2;
  //The following loop checks whether the strings are equal or not and update flag from 1 to 0.
  while(*p!='\0' || *q!='\0')
  {
     if(*p!=*q)
        flag=0;
     p++;
     q++;
  }


  //If flag is 1 then print only first string else print concatenate strings and store it on first string.
  if(flag==1)
  {
     puts(str1);
  }
  else
  {
    p=str1;
    q=str2;
    while(*p!='\0')
       p++;

    while(*q!='\0')
    {
      *p=*q;
      p++;
      q++;
    }
    *p='\0';
    puts(str1);
  }

  return 0;

}