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 c program to calculate sum of digits till it reduces to a single digit using recursion
When is a null pointer used?
What is modeling?
What are conditional operators in C?
What is the difference between formatted&unformatted i/o functions?
What are local variables c?
What is the use of pragma in embedded c?
What is the heap in c?
please explain every phase in the "SDLC" in the dotnet.
What is #include stdio h and #include conio h?
Describe the complexity of Binary search, Quicksort and various other sorting and searching techniques..
What are the advantages of using macro in c language?
Can you please explain the scope of static variables?
praagnovation
write a c program to find the sum of five entered numbers using an array named number