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
Explain how can type-insensitive macros be created?
What are the rules for the identifier?
What are the 4 types of programming language?
What does a function declared as pascal do differently?
How do we open a binary file in Read/Write mode in C?
What are 3 types of structures?
What the different types of arrays in c?
What is a void pointer in c?
write a C program: To recognize date of any format even formats like "feb-02-2003","02-february-2003",mm/dd/yy, dd/mm/yy and display it as mm/dd/yy.
What does the format %10.2 mean when included in a printf statement?
What will the code below print when it is executed? int x = 3, y = 4; if (x = 4) y = 5; else y = 2; printf ("x=%d, y=%d ",x,y);
What is a good data structure to use for storing lines of text?
What is the difference between single charater constant and string constant?
Q.1 write a program to create binary tree 1 to 16 numbers? Q.2 write a program to creat a binary search tree for the member that is given by user?
What does the && operator do in a program code?