Write a program to compare two strings without using the
strcmp() function
Answer Posted / ria varughese
#include <stdio.h>
#include <string.h>
void stringcmp(char s1[], char s2[]);
int main()
{
char str1[10],str2[10];
printf("\nEnter first String:");
scanf("%s",str1);
printf("\nEnter second String:");
scanf("%s",str2);
stringcmp(str1,str2);
return 0;
}
void stringcmp(char *s1, char *s2)
{
int i,j;
for(i=0;s1[i]!='\0';i++)
{
for(j=0;s2[j]!='\0';j++)
{
if(s1[i] == s2[j])
continue;
}
}
if (i==j)
{
printf("String s1:%s and s2:%s are EQUAL\n",s1,s2);
}
else
printf("String s1:%s and s2:%s are NOT EQUAL\n",s1,s2);
}
| Is This Answer Correct ? | 84 Yes | 89 No |
Post New Answer View All Answers
How can I open files mentioned on the command line, and parse option flags?
string reverse using recursion
Some coders debug their programs by placing comment symbols on some codes instead of deleting it. How does this aid in debugging?
Please send me WIPRO technical question to my mail ID.. its nisha_g28@yahoo.com please its urgent
Why is main function so important?
What are the 4 data types?
How can you tell whether a program was compiled using c versus c++?
Should I learn c before c++?
Explain how can I right-justify a string?
while loop contains parts a) initialisation, evalution of an expression,increment /decrement b) initialisation, increment/decrement c) condition evalution d) none of the above
I just typed in this program, and it is acting strangely. Can you see anything wrong with it?
Given only putchar (no sprintf, itoa, etc.) write a routine putlong that prints out an unsigned long in decimal. [ I gave the obvious solution of taking % 10 and / 10, which gives us the decimal value in reverse order. This requires an array since we need to print it out in the correct order. The interviewer wasn't too pleased and asked me to give a solution which didn't need the array ].
Explain how can you tell whether a program was compiled using c versus c++?
Calculate the weighted average of a list of n numbers using the formula xavg = f1x1+f2x2+ ….+ fnxn where the f’s are fractional weighting factors, i.e., 0<=fi<1, and f1+f2+….+fn = 1
Why doesn't C support function overloading?