Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- void reverse(char * c, char limiter)
- {
- int i = 0;
- int j = 0;
- while (*(c+j)!=limiter) j++;
- for (i = 0, j = j - 1; i < j; i++,j--)
- {
- *(c+i) ^= *(c+j);
- *(c+j) ^= *(c+i);
- *(c+i) ^= *(c+j);
- }
- }
- void reverse2(char ** c, int edge)
- {
- int i = 0;
- int j = edge;
- char * temp;
- for (i = 0, j = j - 1; i < j; i++,j--)
- {
- temp = *(c+i);
- *(c+i) = *(c+j);
- *(c+j) = temp;
- }
- }
- char ** transform(char * c)
- {
- int i = 0;
- int start = i;
- char ** words = malloc(sizeof(char*) * 20);
- int j = 0;
- while (*(c+i)!='\0')
- {
- if (*(c+i) == ' ')
- {
- *(c+i) = NULL;
- *(words+j++) = (c+start);
- start = i+1;
- }
- i++;
- }
- if (*(c+start) != NULL)
- {
- *(words+j++) = (c+start);
- start = i+1;
- }
- *(words+j) = NULL;
- return words;
- }
- int finder(char * s, char limiter)
- {
- printf("AAAAAAAAAAAAAAAAAAAAAAAA");
- int i;
- int result;
- i = result = 0;
- while(*(s+i)!='\0')
- {
- if (*(s+i)==' ') result++;
- if (*(s+i)==limiter) break;
- }
- return result;
- }
- void print(char ** words)
- {
- int i = 0;
- while (*(words+i) !=NULL)
- {
- printf("%s ", *(words+i));
- i++;
- }
- }
- int main()
- {
- int edge = 2;
- char ** words;
- char * s;
- s = "I am a coxol person\0";
- printf("%s\n",s);
- edge = finder(s, 'x');
- printf("VVVVVVVVVVVVVVVVVVVVVVVVVVVV");
- words = transform(s);
- reverse2(words,edge);
- print(words);
- return 0;
- }
Add Comment
Please, Sign In to add comment