samir82show

c_ch01_ex17.c

Oct 8th, 2014
188
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.61 KB | None | 0 0
  1. /*Exercise 1-17. Write a program to print all input lines that are longer than 80 characters.*/
  2. #include <stdio.h>
  3. #define MAX 1000
  4. int get_line(char str[], int length);
  5. int main()
  6. {
  7. int length = MAX;
  8. char str[MAX];
  9. while ((length = get_line (str, MAX)) > 0) {
  10. if (length > 80)
  11. printf("%d %s\n", length, str);
  12. }
  13. return 0;
  14. }
  15. int get_line(char str[], int length) {
  16. int c, i = 0;
  17. while ((c = getchar()) != EOF && c != '\n' && i < length - 1)
  18. str[i++] = c;
  19. str[i] = '\0';
  20. return i;
  21. }
Advertisement
Add Comment
Please, Sign In to add comment