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(); ^

Mark Benningfield
  • 2,800
  • 9
  • 31
  • 31
Ayhan Kamil
  • 1
  • 1
  • 1
  • 1
  • 1
    Add a forward declaration of the function prior to main: `void sayHi();` – Chris White May 14 '19 at 17:40
  • ...or move the function to the top of the file, before main(). – Lee Daniel Crocker May 14 '19 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.) – Keith Thompson May 14 '19 at 18:11

1 Answers1

2

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");
}
Yoni Newman
  • 185
  • 13