Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //
- // Lambda
- // Tuesday, Feb 6, 2018
- //
- #include <stdlib.h>
- #include <stdio.h>
- char *getl(FILE* stream)
- {
- int n = 0;
- char c;
- int size = 256;
- char *yeet = malloc(size * sizeof(char));
- if (yeet == NULL)
- return NULL;
- while (c != '\n')
- {
- c = fgetc(stream);
- if (n == size)
- {
- size += 256;
- yeet = realloc(yeet, size * sizeof(char));
- }
- yeet[n] = c;
- n++;
- }
- yeet[n] = '\0';
- return yeet;
- }
- int main()
- {
- char* test = getl(stdin);
- if (test == NULL)
- return 1;
- printf("%s", test);
- free(test);
- return 0;
- }
Add Comment
Please, Sign In to add comment