Bell 32V development
[unix-history] / usr / lib / learn / C / L16.2a
CommitLineData
cb8c26cc
TL
1#print
2Write a program which reads a file with lines of up
3to 200 characters and shortens them to 60 characters
4by throwing away any characters past the first 60.
5Compile and test it; then type "ready".
6#once #create Ref
7hoboken harrison newark roseville avenue grove street
8east orange brick church orange highland avenue east orange
9mountain station south orange maplewood millburn short hills
10summit chatham madison convent station morristown summit cha
11new providence murray hill berkeley heights
12
13gillette stirling millingon lyons basking ridgexxxxxxxxxxxxx
14bernardsville far hills peapack gladstone
15#once #create badin
16hoboken harrison newark roseville avenue grove street
17east orange brick church orange highland avenue east orange brick church orange highland avenue east orange brick church orange highland avenue
18mountain station south orange maplewood millburn short hills
19summit chatham madison convent station morristown summit chatham madison convent station morristown summit chatham madison convent station morristown
20new providence murray hill berkeley heights
21
22gillette stirling millingon lyons basking ridgexxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
23bernardsville far hills peapack gladstone
24#user
25a.out <badin >xxx
26#cmp Ref xxx
27#succeed
28/* one way to do this */
29 \b#include <stdio.h>
30
31main()
32{
33 char line[61];
34 int c, k;
35
36 k = 0;
37 while ((c = getchar()) != EOF) {
38 if (c == '\n') {
39 line[k] = 0;
40 printf("%s\n", line);
41 k = 0;
42 }
43 else if (k < 60)
44 line[k++] = c;
45 }
46}
47
48Note that this version works regardless of
49how long the lines are. If you use getline,
50is the same thing true??
51#log
52#next
5316.2b 10