Learning by doing: Reading books and trying to understand the (code) examples
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

25 lines
525 B

  1. #include <stdlib.h>
  2. #include <stdio.h>
  3. #include <string.h>
  4. #include "getline.h"
  5. int main(void) {
  6. // this is wrong -> realloc in trim() on array which wasn't malloc'ed
  7. // char blub[] = " wurstgesicht";
  8. // printf("%s\n", trim(blub));
  9. // by using return value of getline(), we got an array which was malloc'ed
  10. char *buffer = trim(getLine());
  11. if (buffer == NULL) {
  12. printf("%s\n", "out of memory");
  13. } else {
  14. printf("%s\n", buffer);
  15. free(buffer);
  16. }
  17. return 0;
  18. }