How to compare two strings without using the strcmp() function?
Question: How to compare two strings without using the strcmp() function?
Question:How to compare two strings without using the strcmp() function?
AnswerI have given you a example.In this we compare two strings str1 and str2 without using the strcmp() function.
Example:
#include <stdio.h>
#include <string.h>
void stringcompare(char str1[], char str2[]);
int main()
{
char string1[10],string2[10];
printf("\nEnter first String:");
scanf("%s",string1);
printf("\nEnter second String:");
scanf("%s",string2);
stringcompare(string1,string2);
return 0;
}
void stringcompare(char *str1, char *str2)
{
int i,j;
for(i=0;str1[i]!='\0';i++)
{
for(j=0;str2[j]!='\0';j++)
{
if(str1[i] == str2[j])
continue;
}
}
if (i==j)
{
printf("String str1:%s and str2:%s are EQUAL\n",str1,str2);
}
else
printf("String str1:%s and str2:%s are NOT EQUAL\n",str1,str2);
}
By:Vivek Kr. Agarwal
Date:
How to compare two strings without using the strcmp() function?
Post Your Answers
Related Links
- How to access or modify the constt variable in C ?
- What is an volatile variable?
- How the processor registers can be used in C?
- IF **p and &(*p) are same, than tell how?
- Can you write function similar to printf()?
- How to use functions fseek(), freed(), fwrite() and ftell()?
- What do you understand about datatype?
- What are the data type modifiers?
- what are the constants?Explain in brief?
- How to differentiate b/n definition and declaration?
- How to define their types of variables and initialize them?
- What is type casting?Explain it with an example?
- What are the Array?How to define and declare them?
- What are the Array Indexing?explain.
- What do you understand about String?Explain it.
- What are the reserved Keywords?Explain it.
- What are the ANSI reserved names in C?
- What are the pointers?How to declare them?
- What are the Indirection?Explain with an example?
- What are the Function Pointer?Explain with an example?
- What are the Bit Operators?
- What are the External Variables?
- How to define structure in C?
- How do u understand about structures of arrays?
- How do you define offsetof() Macro?
- What the use of malloc() function?
- What are the different types of malloc() function in C?
- What is the use of calloc() function?
- What are the different type of calloc() function?
- How to use free() function?
- How to differentiate local memory and global memory?
- What is the significance of disk files?
- What are the Text Files and Binary Files?
- What are the temporary disk files?How to create them?
- What are the stream files?
- What are the stdin and stdout file?
- What is the stdaux file?
- What do you understand about Direct port I/O?
- What is the data management?Also define Sorting, merging and purging, Indexed files?
- What are the Linked List?
- What is the Double LinkedList?
- What is the difference b/n Linear search and Binary search?
- What do you understand about B-Tree?
- What is Thrashing?
- What is a pragma?
- What is the difference between the Heap and the Stack?
- Why n++ executes faster than n+1?
- What is the difference b/n a linker and linkage?
- What is the difference b/n run time binding and compile time binding?
- Write algorithm to reverse a singly linked list.
Question:How to compare two strings without using the strcmp() function?