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 the use of #pragma exit?
There seem to be a few missing operators ..
What is enumerated data type in c?
write a program using linked list in which each node consists of following information. Name[30] Branch Rollno Telephone no i) Write the program to add information of students in linked list
Explain the properties of union.
What is the use of clrscr?
Explain the use of fflush() function?
what is the c source code for the below output? 5555555555 4444 4444 333 333 22 22 1 1 22 22 333 333 4444 4444 5555555555
What language is windows 1.0 written?
What are the ways to a null pointer can use in c programming language?
What are the main characteristics of c language describe the structure of ac program?
How do you write a program which produces its own source code as output?
What is the use of function in c?
ATM machine and railway reservation class/object diagram
Program will then find the largest of three numbers using nested if-else statements. User is prompted to enter three numbers. Program will find the largest number and display it on the screen. All three numbers entered by the user are also displayed. If user enters 21, 33, and 5, the output should be as follows: You entered: 21, 33 and 5. The largest number is 33.