Hello I am going through the '"C Programming Language" book and tried this code right out of the text how ever I get this compiler error:
ll.c:6:5: error: conflicting types for ‘getline’
/usr/include/stdio.h:675:20: note: previous declaration of ‘getline’ was here
ll.c:26:7: error: conflicting types for ‘getline’
/usr/include/stdio.h:675:20: note: previous declaration of ‘getline’ was here
I can't imagine that the code in this book is wrong and it look fine to me can anyone see the mistake in this code?
// This program returns the longest line.
#include <stdio.h>
#define MAXLINE 1000
int getline(char line[], int maxline);
void copy(char to[], char from[]);
main() {
int len;
int max;
char line[MAXLINE];
char longest[MAXLINE];
max = 0;
while((len = getline(line, MAXLINE)) > 0)
if(len > max) {
max = len;
copy(longest, line);
}
if(max > 0)
printf("the longest line is %s", longest);
return 0;
}
int getline(char s[], int lim) {
int c, i;
for(i = 0; i < lim-1 && (c=getchar()) != EOF && c != '\n'; i++)
s[i] = c;
if(c == '\n') {
s[i] = c;
i++;
}
s[i] = '\0';
return i;
}
void copy(char to[], char from[]) {
int i;
i = 0;
while((to[i] = from[i]) != '\0')
i++;
}
~
~
~
