first commit!
This commit is contained in:
47
longest_line_extern.c
Normal file
47
longest_line_extern.c
Normal file
@ -0,0 +1,47 @@
|
||||
#include <stdio.h>
|
||||
#define MAXLINE 1000
|
||||
|
||||
int max_len;
|
||||
char current_line[MAXLINE];
|
||||
char longest[MAXLINE];
|
||||
|
||||
int getlime();
|
||||
void copy();
|
||||
|
||||
int main() {
|
||||
int current_len;
|
||||
extern int max_len;
|
||||
extern char longest[];
|
||||
|
||||
max_len = 0;
|
||||
while ((current_len = getlime()) > 0)
|
||||
if (current_len > max_len) {
|
||||
max_len = current_len;
|
||||
copy();
|
||||
}
|
||||
if (max_len > 0) /* there was some line */
|
||||
printf("%s", longest);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int getlime() {
|
||||
int ch, i;
|
||||
extern char current_line[];
|
||||
|
||||
for (i = 0; i < MAXLINE - 1 && (ch = getchar()) != EOF && ch != '\n'; ++i)
|
||||
current_line[i] = ch;
|
||||
if (ch == '\n') {
|
||||
current_line[i] = ch;
|
||||
++i;
|
||||
}
|
||||
current_line[i] = '\0';
|
||||
return i;
|
||||
}
|
||||
|
||||
void copy() {
|
||||
extern char current_line[], longest[];
|
||||
|
||||
for (int i = 0; (longest[i] = current_line[i]) != '\0'; ++i)
|
||||
;
|
||||
}
|
Reference in New Issue
Block a user