Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- int main()
- {
- // Variable declaration and initialization
- int i = 0;
- bool flag = false;
- int length = 0;
- char str[100];
- // Take input from user
- fgets(str, 100, stdin);
- // Prefix matching
- if (str[0] == 'a' && str[1] == 'b')
- {
- printf("Prefix matched");
- }
- else
- {
- printf("Prefix not matched");
- }
- printf("\n\n");
- // Suffix matching
- length = strlen(str)-1;
- if (str[length - 2] == 'a' && str[length - 1] == 'b')
- {
- printf("Suffix matched");
- }
- else
- {
- printf("Suffix not matched");
- }
- printf("\n\n");
- // Substring matching
- for (i = 0; i < length; i++)
- {
- if (str[i] == 'a' && str[i + 1] == 'b')
- {
- flag = true;
- break;
- }
- }
- if (flag)
- {
- printf("Substring matched");
- }
- else
- {
- printf("Substring not matched");
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement