plz check this program and correct the error...im getting around 3 errors. #incl
ID: 3633562 • Letter: P
Question
plz check this program and correct the error...im getting around 3 errors.
#include<stdio.h>
#include<string.h>
int compare(char *,char *);
void main()
{
char string1[20],string2[20];
char p,q;
int l1,l2;
printf(" enter the string1");
gets(string1);
printf(" Enter the string2");
gets(string2);
l1=strlen(string1);
l2=strlen(string2);
if(l1==l2)
compare(&p,&q);
else
printf(" Strings not equal");
}
int compare(char *p,char *q)
{
while(*p!='')
{
if(*p==*q)
{
p++;
q++;
}
printf(" strings equal")
else
break;}
return 0;
}
Explanation / Answer
Run below program it is working now #include #include int compare(char *,char *); void main() { char string1[20],string2[20]; char p,q; int l1,l2,equal; clrscr(); printf(" enter the string1"); gets(string1); printf(" Enter the string2"); gets(string2); l1=strlen(string1); l2=strlen(string2); if(l1==l2) equal=compare(&p,&q); if(equal==0) printf(" string are equal"); else printf(" Strings not equal"); getch(); } int compare(char *p,char *q) { int eq; while(*p!='') { if(*p==*q) { p++; q++; eq=1; } else eq=0; break; } return eq; }Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.