报错信息
error: conflicting types for 'getline'
int getline(char line[], int maxline);
该代码中定义的getline函数和gcc 等编译器,库函数getline函数冲突,改一下函数名字,就可以。
#include <stdio.h>
#define MAXLINE 1000 /* maximum input line length */
int new_getline(char line[], int maxline);
void copy(char to[], char from[]);
/* print the longest input line */
int main()
{
int len;
int max;
char line[MAXLINE];
char longest[MAXLINE]; /* longest line saved here */
/* current line length */
/* maximum length seen so far */
max = 0;
while ((len = new_getline(line, MAXLINE)) > 0)
if (len > max) {
max = len;
copy(longest, line);
}
if(max>0) /*therewasaline*/
printf("%s", longest);
/* current input line */
return 0;
}
/* new_getline: read a line into s, return length */
int new_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;
}
/* copy: copy 'from' into 'to'; assume to is big enough */
void copy(char to[], char from[])
{
int i;
i = 0;
while ((to[i] = from[i]) != '\0')
++i;
}
本文讨论了在C语言编程中遇到的getline函数冲突问题,并提供了通过更改函数名称来解决该问题的方法。
1167

被折叠的 条评论
为什么被折叠?



