简体   繁体   English

“功能”的冲突类型

[英]Conflicting types for 'function'

I'm learning C with "The C programming language" book.我正在用“C 编程语言”书学习 C。 And I'm stucked with this error.我被这个错误困住了。 Here is the code:这是代码:

  #include <stdio.h>
  #define MAXLINE 1000 // Max input line length

  int getline(char line[], int maxline);
  void copy(char to[], char from[]);
  // Printing the longest input line
  int main()
  {
    int len; // Current line length, max line length ever seen
    int max;
    char line[MAXLINE];
    char longest[MAXLINE];

    max = 0;
    while((len = getline(line, MAXLINE)) > 0)
    {
      if(len > max) // If current line length > previous max length - rewrite.
      {
        max = len;
        copy(longest, line);
      }
    }
    if(max > 0) // If there was a line
      printf("%s", longest);
    return 0;
  }

  int getline(char s[],int lim) // return length of line
  {
    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;
  }

This code is an example from the book:) Trying to compile it on Linux: Linux 5.4.97-gentoo.这段代码是书中的一个例子:)试图在 Linux 上编译它:Linux 5.4.97-gentoo。 GCC version: 10.2.0. GCC 版本:10.2.0。

getline is already declared in <stdio.h> . getline已在<stdio.h>中声明。 Change the method name to my_getline .将方法名称更改为my_getline

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM