0

The goal is for the function to say hi ("Hello User"), but it keeps telling me that my sayHi function is invalid. I'm not sure why.

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

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


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

}
Sourav Ghosh
  • 133,132
  • 16
  • 183
  • 261
Red
  • 13
  • 2

2 Answers2

2

You need to either forward declare the function, or put the definition before main(), so that the compiler knows about the function being called.

Sourav Ghosh
  • 133,132
  • 16
  • 183
  • 261
2

You can either try this

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

void sayHi();

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


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

}

or this

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

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

}

int main() {
  sayHi();
  return 0;
}
gunhasiz
  • 118
  • 1
  • 8