Guest User

Untitled

a guest
Jan 18th, 2019
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.05 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <ctype.h>
  4. #include <string.h>
  5.  
  6. char *getline(void){
  7. int i = 0, s = 1, f = 0, j;
  8. char *m, c;
  9. m = (char *) malloc (sizeof(char));
  10. while ((scanf("%c", &m[i]) != EOF)){
  11. i++;
  12. if (s == i) {
  13. m = (char *) realloc (m, 2 * s * sizeof(char));
  14. s *= 2;
  15. }
  16. if(m[i-1] == '\n') break;
  17. f = 1;
  18. }
  19. if (!f) return NULL;
  20. if( !isspace(m[i]) ) m[i+1] = '\0';
  21. for( j = i; j > 0; j--){
  22. if( isspace(m[j]) && !isspace(m[j-1])){
  23. m[i] = '\0';
  24. break;
  25. }
  26. }
  27.  
  28. return m;
  29. }
  30.  
  31. int main(void)
  32. {
  33. freopen("input.txt", "r", stdin);
  34. freopen("output.txt", "w", stdout);
  35. int i = 0, s = 1, j;
  36. char **n;
  37. n = (char **) malloc ( sizeof(char *));
  38. while((n[i]=getline())){
  39. i++;
  40. if (s == i) {
  41. n = (char **) realloc (n, 2 * s * sizeof(char *));
  42. }
  43. }
  44. for( j =i - 1; j >=0 ; j--){
  45. printf("%s", n[j]);
  46. }
  47. return 0;
  48. }
Add Comment
Please, Sign In to add comment