Write a program to compare two strings without using the
strcmp() function
Answer Posted / allen
#include<stdio.h>
#include<conio.h>
void stringcmp(char s1[], char s2[]);
void main()
{
char str1[10],str2[10];
printf("\nEnter first String:");
scanf("%s",str1);
printf("\nEnter second String:");
scanf("%s",str2);
stringcmp(str1,str2);
}
void stringcmp(char *s1, char *s2)
{
int i,j,c=0;
for(i=0,j=0;s1[i]!='\0'||s2[j]!='\0';i++,j++)
{
if(s1[i]!=s2[j])
{
c++;
}
}
if(c==0)
printf("\nstring match");
else
printf("\nstring does not match");
}
| Is This Answer Correct ? | 12 Yes | 4 No |
Post New Answer View All Answers
How can you determine the maximum value that a numeric variable can hold?
How are Structure passing and returning implemented by the complier?
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
How can you find the exact size of a data type in c?
What are structure members?
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
Write a program to swap two numbers without using third variable in c?
What is #pragma statements?
Write a factorial program using C.
Write the test cases for checking a variable having value in range -10.0 to +10.0?
Explain the use of fflush() function?
How do I get an accurate error status return from system on ms-dos?
Is that possible to store 32768 in an int data type variable?
How can a program be made to print the name of a source file where an error occurs?
How can I read and write comma-delimited text?