This is a C Program to perform string matching using String Library. A text and a pattern is given as input. The pattern is searched for in the text and all instances of the pattern are given as output.
Here is source code of the C Program to Perform String Matching Using String Library. The C program is successfully compiled and run on a Linux system. The program output is also shown below.
#include<stdio.h>
int main() {
char str1[30], str2[30];
int i;
printf("\nEnter two strings :");
gets(str1);
gets(str2);
i = 0;
while (str1[i] == str2[i] && str1[i] != '\0')
i++;
if (str1[i] > str2[i])
printf("str1 > str2");
else if (str1[i] < str2[i])
printf("str1 < str2");
else
printf("str1 = str2");
return (0);
}
Output:
$ gcc StringMatchingUsingStringLib.c $ ./a.out Enter two strings : Hingu Pingu str1 < str2
Sanfoundry Global Education & Learning Series – 1000 C Programs.
advertisement
advertisement
Here’s the list of Best Books in C Programming, Data Structures and Algorithms.
If you find any mistake above, kindly email to [email protected]Related Posts:
- Watch Advanced C Programming Videos
- Practice BCA MCQs
- Apply for C Internship
- Check Computer Science Books
- Practice Computer Science MCQs