Advertisement
horselurrver

Doesn't work :(

Aug 13th, 2016
444
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.06 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <string.h>
  3.  
  4. void words(char string[]);
  5. static char *reverse(char string[], int start, int end);
  6. void print(char *string, int start, int end);
  7.  
  8. int main(void){
  9.     words("no way.");
  10.    
  11.     return 0;
  12. }
  13. void print(char *string, int start, int end){
  14.     int x;
  15.     for(x=start; x<end; x++){
  16.         printf("%c", string[x]);
  17.     }
  18.     printf("\n");
  19. }
  20.  
  21. void words(char string[]){
  22.     int x, y=0;
  23.     int length=(int)strlen(string);
  24.     string=reverse(string, 0, length-1);
  25.     printf("here it is:");
  26.     print(string, 0, length);
  27.     for(x=0; x<=length; x++){
  28.         if((x==(length))||(string[x]==' ')){
  29.             string=reverse(string, y, x-1);
  30.             printf("%s\n", string);
  31.             y=x+1;
  32.         }
  33.     }
  34.     print(string, 0, (int)strlen(string));
  35. }
  36.  
  37.  
  38. static char *reverse(char string[], int start, int end){
  39.     int length=(int)strlen(string);
  40.     int i, j;
  41.     static char newstring[50];
  42.     for(i=start, j=end; i<length; i++, j--){
  43.         newstring[i]=string[j];
  44.     }
  45.    
  46.     return newstring;
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement