Lesson 1.1: Hello, world
Lesson 1.1: Hello, world
Lesson 1.1: Hello, world
You also want an ePaper? Increase the reach of your titles
YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.
<strong>Lesson</strong> <strong>1.1</strong>0:<br />
External variables and scopes (1/2)<br />
Programming in C<br />
Prof. Dr. Eike Best<br />
Dr. Elke Wilkeit<br />
September 28, 2002<br />
1 #include <br />
2 #define MAXLINE 1000 /* maximum input line size */<br />
3<br />
4 int cur_max; /* maximum length seen so far */<br />
5 char cur_line[MAXLINE]; /* current input line */<br />
6 char longest[MAXLINE]; /* longest line saved here */<br />
7<br />
8 int getline(void);<br />
9 void copy(void);<br />
10<br />
11 /* print longest input line; specialised version */<br />
12 main()<br />
13 {<br />
14 int cur_len; /* current line length */<br />
15 extern int cur_max;<br />
16 extern char cur_line[];<br />
17 extern char longest[];<br />
18<br />
19 cur_max = 0;<br />
20 while ((cur_len = getline()) > 0)<br />
21 if (cur_len > cur_max) {<br />
22 cur_max = cur_len;<br />
23 copy();<br />
24 }<br />
25 if (cur_max > 0) /* there was a line */<br />
26 printf("%s", longest);<br />
27 return 0;<br />
28 }<br />
29<br />
30 /* getline: specialised version */<br />
31 int getline(void)<br />
32 {<br />
33 int c, i;<br />
34 extern char cur_line[];<br />
35<br />
36 for (i=0; i