Write a program to compare two strings without using the
strcmp() function
Answer Posted / md.ershad.ezaz
int strcompare(char *,char *);
void main()
{
char s1[15],s2[15];
int cmp;
clrscr();
puts("Enter first string");
gets(s1);
puts("Enter second string");
gets(s2);
cmp=strcompare(s1,s2);
if(cmp==0)
puts("strings are equal");
else
puts("strings are not equal");
getch();
}
int strcompare(char *p1,char *p2)
{
while(*p1==*p2)
{
if(*p1=='\0')
return(0);
p1++;
p2++;
}
return(*p1-*p2);
}
| Is This Answer Correct ? | 4 Yes | 1 No |
Post New Answer View All Answers
What do you understand by friend-functions? How are they used?
Is c compiled or interpreted?
What is the purpose of main() function?
What is meant by gets in c?
What header files do I need in order to define the standard library functions I use?
What does the c preprocessor do?
What is static and auto variables in c?
You are to write your own versions of strcpy() and strlen (). Call them mystrcpy() and mystrlen(). Write them first as code within main(), not as functions, then, convert them to functions. You will pass two arrays to the function in the case of mystrcpy(), the source and target array.
What does void main () mean?
Is null valid for pointers to functions?
Write a program, where i have a grid with many cells, how many paths are possible from one point to other desired points.
How many keywords (reserve words) are in c?
What is p in text message?
Why pointers are used?
How do you define structure?