我正在尝试运行以下代码,该代码搜索行列表中的最长行并复制/保存它。
int getline(char line[], int maxline);
void copy(char to[], char from[]);
int main()
{
int len; /* current line length */
int max; /* maximum length seen so far */
char line[MAXLINE]; /* current input line */
char longest[MAXLINE]; /* longest line saved here */
max = 0;
while ((len = getline(line, MAXLINE)) > 0)
if (len > max) {
max = len;
copy(longest, line);
}
if (max > 0) /* there was a line */
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;
}
但编译器说getline
存在错误,其中类型存在冲突。
所以主要是getline()
通过处理其中的字符数来获取行列表中最长行。
答案 0 :(得分:0)
它之间存在冲突,因为您重新定义原始libc函数import { Button} from 'native-base';
<Button>
<Text>Submit</Text>
</Button>
的原型,其原型在getline()
中定义。
来自<stdio.h>
我们有:
man 3 getline
如果您使用ssize_t getline(char **lineptr, size_t *n, FILE *stream);
重新定义它,则会与原始int getline(char line[], int maxline)
功能发生冲突。
只需重命名您的功能,使其不与库发生冲突。