Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * Exercise 1-17.
- * Write a program to print all input lines that are longer than 80 characters.
- */
- #include <stdio.h>
- #define MAXLINE 1000 /* 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) {
- if (len > 80)
- printf("%s", line);
- }
- return (0);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement