Guest User

Untitled

a guest
Jan 20th, 2019
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.42 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4.  
  5. void reverse(char * c, char limiter)
  6. {
  7.     int i = 0;
  8.     int j = 0;
  9.     while (*(c+j)!=limiter) j++;
  10.    
  11.     for (i = 0, j = j - 1; i < j; i++,j--)
  12.     {
  13.         *(c+i) ^= *(c+j);
  14.         *(c+j) ^= *(c+i);
  15.         *(c+i) ^= *(c+j);
  16.     }
  17. }
  18.  
  19. void reverse2(char ** c, int edge)
  20. {
  21.     int i = 0;
  22.     int j = edge;
  23.    
  24.     char * temp;
  25.     for (i = 0, j = j - 1; i < j; i++,j--)
  26.     {
  27.         temp = *(c+i);
  28.         *(c+i) = *(c+j);
  29.         *(c+j) = temp;
  30.     }
  31. }
  32.  
  33. char ** transform(char * c)
  34. {
  35.     int i = 0;
  36.     int start = i;
  37.     char ** words = malloc(sizeof(char*) * 20);
  38.     int j = 0;
  39.     while (*(c+i)!='\0')
  40.     {
  41.         if (*(c+i) == ' ')
  42.         {
  43.             *(c+i) = NULL;
  44.             *(words+j++) = (c+start);
  45.             start = i+1;
  46.         }
  47.         i++;
  48.     }
  49.    
  50.     if (*(c+start) != NULL)
  51.     {
  52.         *(words+j++) = (c+start);
  53.         start = i+1;
  54.     }
  55.     *(words+j) = NULL;
  56.    
  57.     return words;
  58. }
  59.  
  60. int finder(char * s, char limiter)
  61. {
  62.     printf("AAAAAAAAAAAAAAAAAAAAAAAA");
  63.     int i;
  64.     int result;
  65.     i = result = 0;
  66.     while(*(s+i)!='\0')
  67.     {
  68.         if (*(s+i)==' ') result++;
  69.         if (*(s+i)==limiter) break;
  70.     }
  71.     return result;
  72. }
  73.  
  74. void print(char ** words)
  75. {
  76.     int i = 0;
  77.     while (*(words+i) !=NULL)
  78.     {
  79.         printf("%s ", *(words+i));
  80.         i++;
  81.     }
  82. }
  83.  
  84. int main()
  85. {
  86.     int edge = 2;
  87.     char ** words;
  88.     char * s;
  89.    
  90.     s = "I am a coxol person\0";
  91.     printf("%s\n",s);
  92.     edge = finder(s, 'x');
  93.     printf("VVVVVVVVVVVVVVVVVVVVVVVVVVVV");
  94.     words = transform(s);
  95.     reverse2(words,edge);
  96.     print(words);
  97.  
  98.     return 0;
  99. }
Add Comment
Please, Sign In to add comment