Last active
January 6, 2020 14:03
-
-
Save mrcat323/dc20c1ee153c0c0aa18df5ee401be11b to your computer and use it in GitHub Desktop.
Extern. first file is from book, second is mine
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#define MAX 1000 | |
int i; | |
char line[MAX]; | |
char longest[MAX]; | |
int length(void); | |
void copy(void); | |
int main(void) | |
{ | |
int max; | |
while (length()) { | |
if (i > max) { | |
max = i; | |
copy(); | |
} | |
} | |
printf("%s", longest); | |
} | |
int length(void) | |
{ | |
int c; | |
for (i = 0; i < MAX - 1 && (c = getchar()) != EOF && c != '\n'; ++i) | |
line[i] = c; | |
if (c == '\n') | |
line[i++] = c; | |
line[i] = '\0'; | |
} | |
void copy(void) | |
{ | |
int j = 0; | |
while ((longest[j] = line[j]) != '\0') | |
++j; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#define MAX 1000 | |
int max; | |
char longest[MAX]; | |
char line[MAX]; | |
int length(void); | |
void copy(void); | |
int main(void) | |
{ | |
int len; | |
extern int max; | |
extern char longest[]; | |
while (len = length()) { | |
if (len > max){ | |
max = len; | |
copy(); | |
} | |
} | |
printf("%s", longest); | |
return 0; | |
} | |
int length(void) | |
{ | |
int i, c; | |
for (i = 0; i < MAX - 1 && (c = getchar()) != EOF && c != '\n'; ++i) | |
line[i] = c; | |
if (c == '\n') | |
line[i++] = c; | |
line[i] = '\0'; | |
return i; | |
} | |
void copy(void) | |
{ | |
int i = 0; | |
extern char line[]; | |
extern char longest[]; | |
while ((longest[i] = line[i]) != '\0') | |
++i; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#define MAX 1000 | |
int max; | |
char longest[MAX]; | |
char line[MAX]; | |
int length(void); | |
void copy(void); | |
void reverse(void); | |
int main(void) | |
{ | |
int len; | |
extern int max; | |
extern char longest[]; | |
max = 0; | |
while (len = length()) { | |
if (len > max) { | |
max = len; | |
copy(); | |
} | |
} | |
printf("%s", longest); | |
reverse(); | |
return 0; | |
} | |
int length(void) | |
{ | |
int i, c; | |
extern char line[]; | |
for (i = 0; i < MAX - 1 && (c = getchar()) != EOF && c != '\n'; ++i) | |
line[i] = c; | |
if (c == '\n') | |
line[i++] = c; | |
line[i] = '\0'; | |
return i; | |
} | |
void copy(void) | |
{ | |
int i = 0; | |
extern char line[], longest[]; | |
while ((longest[i] = line[i]) != '\0') | |
++i; | |
} | |
void reverse(void) | |
{ | |
extern int max; | |
extern char longest[]; | |
char reverse[MAX]; | |
int j, i; | |
for (i = max - 1, j = 0; j < max; ++j, --i) | |
reverse[j] = longest[i]; | |
printf("%s", reverse); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment