Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <string.h>
- int findString(char source1[], char source2[]);
- int main()
- {
- char x[] = "a chatterbox";
- char y[] = "hat";
- int z = findString(x, y);
- printf("%d\n", z);
- return 0;
- }
- int findString(char source1[], char source2[])
- {
- int flag = 1;
- int i = 0;
- int j = 0;
- int counter = 0;
- while(source1[i] != '\0' && j < strlen(source2))
- {
- if(flag == 1)
- {
- if(source1[i] == source2[j])
- {
- flag = 1;
- i++;
- j++;
- }
- else
- {
- flag = 0;
- j = 0;
- }
- }
- else
- {
- if(source1[i] == source2[j])
- {
- flag = 1;
- counter = i;
- }
- else
- {
- i++;
- }
- }
- }
- if(flag == 1)
- {
- return counter;
- }
- else
- return -1;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement