Created
October 7, 2015 04:17
-
-
Save Technicus/c8e2baa0226c1dc6aca7 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <stdio.h> | |
| #include <stdlib.h> | |
| // function declerations | |
| void readString(void); | |
| // function definitions | |
| void readString(){ | |
| char *line = NULL; /* forces getline to allocate with malloc */ | |
| size_t len = 0; /* ignored when line = NULL */ | |
| ssize_t read; | |
| printf ("\n\tEnter string below [ctrl + d] to quit\n\t\tString > "); | |
| read = getline(&line, &len, stdin); | |
| /* Remove trailing newline character from the input buffer if needed. */ | |
| if (line[len] == '\n'){ | |
| line[len] = '\0'; | |
| } | |
| printf ("\n\tRead %zd chars from stdin, allocated %zd bytes for line: \"%s\"\n\n", read, len, line); | |
| } | |
| int main (int argc, char *argv[]) { | |
| readString(); | |
| return 0; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment