Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<stdio.h>
- #include<string.h>
- #include<stdlib.h>
- #define SIZE 20
- char* GetSameChars(char* str1, char* str2);
- int main()
- {
- char *string1, *string2;
- puts(GetSameChars(&string1, &string2));
- system("pause");
- }
- char* GetSameChars(char* str1, char* str2)
- {
- char buffer1[SIZE], buffer2[SIZE];
- printf("Enter array number 1:\n");
- gets_s(buffer1, SIZE);
- str1 = (char*)malloc(strlen(buffer1) + 1);
- strcpy_s(str1,SIZE, buffer1);
- printf("Enter array number 2:\n");
- gets_s(buffer2, SIZE);
- str2 = (char*)malloc(strlen(buffer2) + 1);
- strcpy_s(str2, SIZE, buffer2);
- int i = 0;
- int j = 0;
- int k = 0;
- char *arr=0;
- while (1)
- {
- if (str1[i] == str2[j])
- {
- arr[k] = str2[j];
- k++;
- j++;
- }
- else
- i++;
- if (i == strlen(str1) || j == strlen(str2));
- break;
- }
- arr=(char*)malloc(k*sizeof(char));
- return arr;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement