Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- void clean_buffer()
- {
- int c;
- while((c = getchar()) != '\n');
- }
- int substr(char* str1, char* str2, int** result);
- int main()
- {
- int str1_len;
- int str2_len;
- scanf("%i %i", &str1_len, &str2_len);
- clean_buffer();
- char* str1;
- char* str2;
- str1=malloc((str1_len+1)*sizeof(char));
- str2=malloc((str2_len+1)*sizeof(char));
- for(int i=0;i<str1_len;i++){
- scanf("%c",&str1[i]);
- }
- clean_buffer();
- str1[str1_len]='\0';
- for(int i=0;i<str2_len;i++){
- scanf("%c",&str2[i]);
- }
- str2[str2_len]='\0';
- int* result;
- int arr_len = substr(str1, str2, &result);
- int i = 0;
- for(i = 0; i < arr_len; i++)
- printf("%i ", result[i]);
- free(result);
- free(str1);
- free(str2);
- }
- int substr(char* str1, char* str2, int** result)
- {
- int maxsize=strlen(str2);
- int count=-1;
- int* listof = malloc(maxsize*sizeof(int));
- for(int i=0;i<strlen(str2);i++){
- if(str2[i]==str1[0]){
- int ch=1;
- for(int j=0;j<strlen(str1);j++){
- if(str2[i+j]!=str1[j]){
- ch=0;
- break;
- }
- }
- if(ch==0){
- continue;
- }else{
- count++;
- listof[count]=i;
- }
- }
- }
- *result=listof;
- return count+1;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement