Write a program to compare two strings without using the
strcmp() function
Answer Posted / fionaa
int compare(char str2[], char str1[]) {
int flag = -1;
int i=0;
while(str1[i]!='\0' && str2[i]!='\0'){
if((str1[i]==str2[i])) {flag = 0;}
else if (str1[i]>str2[i]) {
flag=-1;
break;
}else if(str1[i]<str2[i]){
flag = 1;
break;
}
i++;
}
if(strlen(str1)==strlen(str2) && flag==0 ){
flag = 0;
}
else if(strlen(str1)>strlen(str2) && flag==0 ){
flag = 1;
}
else {flag = -1;}
return flag;
}
| Is This Answer Correct ? | 0 Yes | 1 No |
Post New Answer View All Answers
Write a program to input the price of 1 burger and the number of burgers eaten by a group of friends .print the total amount to be paid by the group?
What is meant by gets in c?
Explain what is the difference between far and near ?
What are identifiers and keywords in c?
Find MAXIMUM of three distinct integers using a single C statement
Describe wild pointers in c?
Explain what is meant by 'bit masking'?
Does c have function or method?
int i[2], j; int *pi;i[0] = 1; i[1] = 5; pi = i; j = *pi + 1 + *(pi + 1)Value of j after execution of the above statements will be a) 7 b) 6 c) 4 d) pointer
When should a far pointer be used?
When is a void pointer used?
What is a stream water?
HOW TO SOLVE A NUMERICAL OF LRU IN OS ??????
What is a global variable in c?
How can I rethow can I return a sequence of random numbers which dont repeat at all?