0

I am a complete beginner and have been taking youtube lessons on C. However I am stuck with a very basic error (I assume) and would appreciate an explanation of why I am getting this error:

I haven't tried any fixes as I have no clue - being a complete beginner.

#include <stdio.h>
#include <stdlib.h>

int main()
{
  sayHi();
  return 0;
}   


void sayHi()
{
 printf("Hello User");
}

f.c:6:5: error: implicit declaration of function 'sayHi' is invalid in C99 [-Werror,-Wimplicit-function-declaration] sayHi(); ^ f.c:11:6: error: conflicting types for 'sayHi' void sayHi() ^ f.c:6:5: note: previous implicit declaration is here sayHi(); ^

3
  • 1
    Add a forward declaration of the function prior to main: void sayHi(); Commented May 14, 2019 at 17:40
  • ...or move the function to the top of the file, before main(). Commented May 14, 2019 at 17:47
  • Empty parentheses () on a function declaration mean that it takes an unspecified number and type(s) of arguments. That's an obsolescent feature. To specify that the function takes no arguments (and get better compile-time checking), use int main(void) and void sayHi(void). (Note that in C++, empty parentheses do mean that the function takes no arguments.) Commented May 14, 2019 at 18:11

1 Answer 1

3

Declare SayHi function before you call it.

#include <stdio.h>
#include <stdlib.h>

void sayHi(); //declartion of the function

int main()
{
sayHi();
return 0;
}   


void sayHi()
{
printf("Hello User");
}
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.