#simple compilation type error

7 messages · Page 1 of 1 (latest)

hot radish
#

Started learning C recently. I don't get what the problem is here:

#include <stdio.h>

#define MAXLINE 1000

void count(char *);

void getline(char s[]) {
    char c;
    int i = 0;
    while ((c = getchar()) != EOF) {
        s[i] = c;
        ++i;
    }
}

int main() {
    char line[MAXLINE];
    
//    getline(line);    
    printf(line);
    printf("\n");
    count(line);
}

void count(char s[]) {
    s[0] = 'a';
    s[1] = 'b';
    s[2] = 'c';
    printf(s);
    printf("\n");
}

error:

concepts/6-character-arrays.c:7:6: error: conflicting types for ‘getline’; have ‘void(char *)’
    7 | void getline(char s[]) {
      |      ^~~~~~~
In file included from concepts/6-character-arrays.c:1:
/usr/include/stdio.h:645:18: note: previous declaration of ‘getline’ with type ‘__ssize_t(char ** restrict,  size_t * restrict,  FILE * restrict)’ {aka ‘long int(char ** restrict,  long unsigned int * restrict,  FILE * restrict)’}
  645 | extern __ssize_t getline (char **__restrict __lineptr,
deep saddleBOT
#

When your question is answered use !solved to mark the question as resolved.

Remember to ask specific questions, provide necessary details, and reduce your question to its simplest form. For tips on how to ask a good question run !howto ask.

sweet crystal
#

getline is the name of a library function that already exists in stdio.h

#

You are not allowed to have two functions of the same name (even if one of them is from a library you are using)

#

rename your function and you should be good

hot radish
#

oh i see, thanks

#

!solved