Guest User

Untitled

a guest
Feb 19th, 2018
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.77 KB | None | 0 0
  1. //
  2. // Lambda
  3. // Tuesday, Feb 6, 2018
  4. //
  5. #include <stdlib.h>
  6. #include <stdio.h>
  7.  
  8. char *getl(FILE* stream)
  9. {
  10. int n = 0;
  11. char c;
  12. int size = 256;
  13. char *yeet = malloc(size * sizeof(char));
  14. if (yeet == NULL)
  15. return NULL;
  16.  
  17. while (c != '\n')
  18. {
  19. c = fgetc(stream);
  20. if (n == size)
  21. {
  22. size += 256;
  23. yeet = realloc(yeet, size * sizeof(char));
  24. }
  25. yeet[n] = c;
  26. n++;
  27. }
  28. yeet[n] = '\0';
  29.  
  30. return yeet;
  31. }
  32.  
  33. int main()
  34. {
  35. char* test = getl(stdin);
  36. if (test == NULL)
  37. return 1;
  38.  
  39. printf("%s", test);
  40. free(test);
  41. return 0;
  42. }
Add Comment
Please, Sign In to add comment