Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<stdio.h>
- #include<math.h>
- #include<malloc.h>
- #include<windows.h>
- int getLength(char* str)
- {
- int length = 0;
- while(str[length++]);
- return length-1;
- }
- char* getString(char* str)
- {
- str = (char*)malloc(sizeof(char));
- int i = 1;
- char c = ' ';
- while((c = getchar())!= '\n')
- {
- str[i-1] = c;
- i++;
- realloc(str,sizeof(char)*i);
- str[i-1] = '\0';
- }
- return str;
- }
- char* copy(char* str1,char* str2)
- {
- free(str1);
- int len2 = getLength(str2);
- str1 = (char*)malloc(sizeof(char)*len2);
- for(int i = 0;i<len2;i++)
- {
- str1[i] = str2[i];
- }
- str1[len2] = '\0';
- return str1;
- }
- int find(char* str,char c)
- {
- for(int i = 0;i<getLength(str);i++)
- {
- if(str[i] == c) return i;
- }
- return -1;
- }
- int main()
- {
- printf("str1: ");
- char* str1 = getString(str1);
- printf("str2: ");
- char* str2 = getString(str2);
- int len1 = getLength(str1);
- //printf("%s\n",str1);
- //printf("%s",str2);
- /*
- int n = 0;
- printf("n: ");
- scanf("%i",&n);
- char* str3 = (char*)malloc(sizeof(char)*(len1+n+1));
- for(int i = 0;i<len1;i++)
- {
- str3[i] = str1[i];
- }
- for(int i = 0;i<n;i++)
- {
- str3[len1 + i] = str2[i];
- }
- str3[len1+n] = '\0';
- //printf("%s",str3);
- str1 = copy(str1,str3);
- printf("str1 = %s\n",str1);
- char c = ' ';
- fflush(stdin);
- printf("Enter symbol: ");
- scanf("%c",&c);
- int index = 0;
- if((index = find(str1,c))!=-1)
- {
- printf("index first entrance: %i",index);
- }else printf("not found");
- int lengthLine = 0;
- for(int i = 0;i<getLength(str1);i++)
- {
- for(int j = 0;j<getLength(str2);j++)
- {
- if(str1[i] == str2[j])
- {
- lengthLine++;
- break;
- }
- }
- }
- printf("\nlength of line %i",lengthLine);
- */
- char word[255];
- int indexWord = 0;
- for(int i = 0;i<getLength(str1);i++)
- {
- if(find(str2,str1[i]) == -1)
- {
- word[indexWord++] = str1[i];
- }
- else if(indexWord !=0 )
- {
- word[indexWord] = '\0';
- printf("%s\n",word);
- indexWord = 0;
- }
- }
- if(indexWord != 0)
- {
- word[indexWord] = '\0';
- printf("%s\n",word);
- }
- free(str1);
- free(str2);
- //free(str3);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement