#include"stdio.h"
#include"conio.h"
#include"malloc.h"
int main()
{
char *firstString =(char*)malloc(100);
char *secondString =(char*)malloc(100);
void readString(char *);
void printString(char *);
int stringCompare(char *,char *);
int result;
clrscr();
printf("\nEnter First String : ");
readString(firstString);
printf("\nEnter Second String : ");
readString(secondString);
result=stringCompare(firstString,secondString);
if(result!=0)
printf("\nString are not equal");
else
printf("\nStrings are equal");
getch();
return 1;
}
//Function readString
void readString(char *s)
{
while((*s=getchar())!='\n') // Read until user press enter key
*s++;
*s=NULL;
}
//Function printString
void printString(char *s)
{
while(*s!=NULL)
putchar(*s++);
}
{
while(*first&&*second)
if(*first++!=*second++)
return 1;
return 0;
}
#include"conio.h"
#include"malloc.h"
int main()
{
char *firstString =(char*)malloc(100);
char *secondString =(char*)malloc(100);
void readString(char *);
void printString(char *);
int stringCompare(char *,char *);
int result;
clrscr();
printf("\nEnter First String : ");
readString(firstString);
printf("\nEnter Second String : ");
readString(secondString);
result=stringCompare(firstString,secondString);
if(result!=0)
printf("\nString are not equal");
else
printf("\nStrings are equal");
getch();
return 1;
}
//Function readString
void readString(char *s)
{
while((*s=getchar())!='\n') // Read until user press enter key
*s++;
*s=NULL;
}
//Function printString
void printString(char *s)
{
while(*s!=NULL)
putchar(*s++);
}
//Compare to string and returns 0 if they are equal else return 1
int stringCompare(char *first,char *second){
while(*first&&*second)
if(*first++!=*second++)
return 1;
return 0;
}
No comments:
Post a Comment