Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- /* practice file for learning to program in C */
- int getLine(char line[], int max);
- int main(int argc, char **argv)
- {
- char line[256];
- while(getline(line, 256) != EOF)
- printf("you typed \"%s\"\n", line);
- return 0;
- }
- // function for reading one line of input at a time
- int getLine(char line[], int max)
- {
- int nch = 0;
- int c;
- max = max - 1; /* leaves room for '\0' */
- while ((c = getchar()) != EOF) {
- if (c == '\n')
- break;
- if (nch < max) {
- line[nch] = c;
- nch++;
- }
- }
- if (c == EOF && nch == 0)
- return EOF;
- line[nch] = '\0';
- return nch;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement