ReverseFlux

strings

Feb 3rd, 2017
173
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.62 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4. int main (int argc, char *argv[]) {
  5.  
  6. char *line = NULL; /* forces getline to allocate with malloc */
  7. size_t len = 0; /* ignored when line = NULL */
  8. ssize_t read;
  9.  
  10. printf ("\nEnter string below [ctrl + d] to quit\n");
  11.  
  12. while ((read = getline(&line, &len, stdin)) != -1) {
  13.  
  14. if (read > 0)
  15. printf ("\n read %zd chars from stdin, allocated %zd bytes for line : %s\n", read, len, line);
  16.  
  17. printf ("Enter string below [ctrl + d] to quit\n");
  18. }
  19.  
  20. free (line); /* free memory allocated by getline */
  21.  
  22. return 0;
  23. }
Advertisement
Add Comment
Please, Sign In to add comment