Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void stdin_function () {
- char *ch;
- int size = 10;
- int new_line = 0; //number of new lines
- ch = malloc (size * sizeof(char));
- int i;
- for (i = 0;scanf("%c",&ch[i]) != EOF;i++) {
- if(i >= size) {
- size += 2;
- ch = realloc (ch,size);
- }
- }
- int reverse = i - 1; //counts in the reversed loop (i-1) is because we want the index
- char arr[size]; //static arr with capacity size
- int br = -1; //the counter which will be used to go through arr
- for(;reverse != -1; reverse --) { // -1 we want to read the 0 element too
- if(ch[reverse] == '\n') {
- new_line ++;
- if (new_line == 11) break; //breaks if we have read 10 \n
- }
- arr[++br] = ch[reverse]; //++br to become 0 in the beginning and to have br as the index not the size
- }
- for (; br > -1 ;br -- ) {
- write(STDOUT_FILENO,&arr[br],1);
- }
- free(ch);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement