Write a program to compare two strings without using the
strcmp() function
Answer Posted / shashi
#include<stdio.h>
#include<conio.h>
int 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);
if (stringcmp(str1,str2))
{
printf("String s1:%s and s2:%s are EQUAL\n",str1,str2);
}
else
printf("String s1:%s and s2:%s are NOT EQUAL\n",str1,str2);
getch();
return 0;
}
int stringcmp(char *s1, char *s2)
{
int flag=0;
char *count;
count=s1;
while(*count++)
{
flag=0;
if(*s1++==*s2++)
{
flag=1;
}
}
return flag;
}
| Is This Answer Correct ? | 4 Yes | 1 No |
Post New Answer View All Answers
Explain about the constants which help in debugging?
What is a pointer and how it is initialized?
What is the explanation for the dangling pointer in c?
Differentiate between functions getch() and getche().
Explain the advantages of using macro in c language?
Write a client and server program in C language using UDP, where client program interact with the Server as given below: i) The client begins by sending a request to send a string of 8 characters or series of 7 numbers, the server sends back a characters or numbers as per the request of the client. ii) In case of series of 7 numbers: The client sends a multiplication of numbers, to the server. iii) In case of a string of 8 characters: The client sends a reverse order of string to the server.. iv) Server will send an acknowledgment to the client after receiving the correct answer
Is it better to bitshift a value than to multiply by 2?
Why does this code crash?
main() { printf("hello"); fork(); }
what is event driven software and what is procedural driven software?
can any one tel me wt is the question pattern for NIC exam
Explain with the aid of an example why arrays of structures don’t provide an efficient representation when it comes to adding and deleting records internal to the array.
How can I read and write comma-delimited text?
What is the difference between constant pointer and constant variable?
What are the types of data structures in c?