简体   繁体   中英

Conflicting types for 'function'

I'm learning C with "The C programming language" book. 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. GCC version: 10.2.0.

getline is already declared in <stdio.h> . Change the method name to my_getline .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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