"The C Programming Language"섹션 1.9에서 곧바로 실행하려고하는 프로그램이 있습니다. 나는 우분투 11.10를 사용하여 프로그램을 컴파일 할 때 여기 K & R2 1 장에서 가장 긴 행 예제를 컴파일 할 때 "getline에 대해 충돌하는 유형"오류가 발생하는 이유는 무엇입니까?
#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("%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;
}
은 내가 오류입니다 :
cc word.c -o word
word.c:4:5: error: conflicting types for ‘getline’
/usr/include/stdio.h:671:20: note: previous declaration of ‘getline’ was here
word.c:26:5: error: conflicting types for ‘getline’
/usr/include/stdio.h:671:20: note: previous declaration of ‘getline’ was here
make: *** [word] Error 1
그냥 확인이 책의 인쇄에 문제가 아니었다 만들을, 나는 참조 이 장의 뒷부분에 나오는 답변 세트 (http://users.powernet.co.uk/eton/kandr2/krx1.html)와 연습 문제 18, 19, 20을 실행하려고하면 비슷한 오류가 발생합니다. , 21, 등등. 프로그램을 실행하여 출력하는 방법을 알 수 없을 때 배울 수 없습니다. 이 문제는 문자 배열과 함수 호출을 하나의 프로그램에 도입 할 때 시작되었습니다. 이 문제에 대한 조언을 주시면 감사하겠습니다.
낭비 20 분. google 그냥 –
하 하하 나도 @ dmtri.com – samrap
** getline() ** ** ** 표준 라이브러리 함수가 아니라, 그것은 @moooeeeep 더 깊이와 또한 여기에 http : //Dackerup.asp에 의해 /standackflow.com/questions/7376566/can-an-ans-c-compliant-implementation-include-additional-functions-in-stand-stand 따라서 오늘 코딩을한다면'getline()'을 사용하지 말아야한다. 그러나 이미 자체 구현 된'getline()'함수를 사용하는 라이브러리에 의존한다면 어떻게 될까? 광범위한 의미에서 @ moooeeeep의 대답이 더 적절하다고 생각합니다. –