Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * Exercise 1-16.
- * Revise the main routine of the longest-line program so it will correctly
- * print the length of arbitrary long input lines, and as much as possible of
- * the text.
- */
- #include <stdio.h>
- #define MAXLINE 20 /* maximum input line length */
- /* getline: read a line into s, return length */
- int
- get_line(char s[], int lim)
- {
- int c, i, j;
- j = 0;
- for (i = 0; (c = getchar()) != EOF && c != '\n'; ++i) {
- if (i < lim -2) {
- s[j++] = c;
- }
- }
- if (c == '\n') {
- s[j++] = c;
- }
- s[j] = '\0';
- return (i);
- }
- int
- main()
- {
- int len;
- char line[MAXLINE];
- while ((len = get_line(line, MAXLINE)) > 0) {
- printf("TL[%3d] %s", len, line);
- }
- return (0);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement