Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <ctype.h>
- #include <string.h>
- char *getline(void){
- int i = 0, s = 1, f = 0, j;
- char *m, c;
- m = (char *) malloc (sizeof(char));
- while ((scanf("%c", &m[i]) != EOF)){
- i++;
- if (s == i) {
- m = (char *) realloc (m, 2 * s * sizeof(char));
- s *= 2;
- }
- if(m[i-1] == '\n') break;
- f = 1;
- }
- if (!f) return NULL;
- if( !isspace(m[i]) ) m[i+1] = '\0';
- for( j = i; j > 0; j--){
- if( isspace(m[j]) && !isspace(m[j-1])){
- m[i] = '\0';
- break;
- }
- }
- return m;
- }
- int main(void)
- {
- freopen("input.txt", "r", stdin);
- freopen("output.txt", "w", stdout);
- int i = 0, s = 1, j;
- char **n;
- n = (char **) malloc ( sizeof(char *));
- while((n[i]=getline())){
- i++;
- if (s == i) {
- n = (char **) realloc (n, 2 * s * sizeof(char *));
- }
- }
- for( j =i - 1; j >=0 ; j--){
- printf("%s", n[j]);
- }
- return 0;
- }
Add Comment
Please, Sign In to add comment