Mary_99

TASK 1/2

Jan 31st, 2019
48
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.98 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. void split(char word[],char separators[],int offset[]){
  4.     int length = strlen(word);
  5.     int length2 = strlen(separators);
  6.     int k=0;
  7.     int i;
  8.     int j;
  9.     for(i=0; i<length; i++){
  10.         for(j=0; j<length2; j++){
  11.             if(word[i] == separators[j]){
  12.                 offset[k]=i;
  13.                 k++;
  14.                 break;
  15.             }
  16.         }
  17.     }
  18.     if(offset[0]!=NULL){
  19.     printf("separators detected at: ");
  20.     for( i=0; i<k; i++){
  21.         printf("(position %d, word[%d]) ", offset[i]+1, offset[i]);
  22.     }
  23.     }
  24.     else
  25.         printf("no separators detected");
  26. }
  27. int main()
  28. {   int i;
  29.     char word[100];
  30.     char separators[100] = {' ', '.', ','};
  31.     int offset[100];
  32.     printf("Separators: ");
  33.     for(i=0; i<strlen(separators); i++){
  34.         printf("'%c' ", separators[i]);
  35.     }
  36.     printf("Enter a sentence: ");
  37.     fgets(word, 100, stdin);
  38.     split(word, separators, offset);
  39.     return 0;
  40. }
Add Comment
Please, Sign In to add comment