Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
oorrja
GitHub Repository: oorrja/learntosolveit
Path: blob/master/languages/cprogs/Ex_1.17_lengt80.c
1240 views
1
/**
2
*
3
* Exercise 1.17 - Program to print the length of all input lines greater
4
* than 80 characters.
5
*
6
**/
7
8
#include<stdio.h>
9
10
#define MAXLINE 1000
11
#define LIMIT 80
12
13
14
/***
15
*
16
* We call it ngetline, for new getline so that it does not conflict with
17
* system function getline
18
*
19
***/
20
21
int ngetline(char line[], int lim);
22
23
24
int main(void)
25
{
26
int len;
27
char line[MAXLINE];
28
29
while((len = ngetline(line,MAXLINE)) > 0)
30
{
31
if( len > LIMIT )
32
printf("%s",line);
33
}
34
35
return 0;
36
}
37
38
39
int ngetline(char s[], int lim)
40
{
41
int i, c;
42
43
for(i = 0; i < lim-1 && ( c = getchar() )!= EOF && c!='\n'; ++i)
44
s[i] = c;
45
46
if(c == '\n')
47
{
48
s[i] = c;
49
++i;
50
}
51
s[i] = '\0';
52
53
return i;
54
}
55
56
57