Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- void split(char word[],char separators[],int offset[]){
- int length = strlen(word);
- int length2 = strlen(separators);
- int k=0;
- int i;
- int j;
- for(i=0; i<length; i++){
- for(j=0; j<length2; j++){
- if(word[i] == separators[j]){
- offset[k]=i;
- k++;
- break;
- }
- }
- }
- if(offset[0]!=NULL){
- printf("separators detected at: ");
- for( i=0; i<k; i++){
- printf("(position %d, word[%d]) ", offset[i]+1, offset[i]);
- }
- }
- else
- printf("no separators detected");
- }
- int main()
- { int i;
- char word[100];
- char separators[100] = {' ', '.', ','};
- int offset[100];
- printf("Separators: ");
- for(i=0; i<strlen(separators); i++){
- printf("'%c' ", separators[i]);
- }
- printf("Enter a sentence: ");
- fgets(word, 100, stdin);
- split(word, separators, offset);
- return 0;
- }
Add Comment
Please, Sign In to add comment