Basic multi module problem

I am trying to learn how to use multiple modules and hearder files. I have tried a little experiment but cannot get it to work. Here is my code and compilation attempt. Any help with finding my problems appreciated.

The main function (main01.c) calls a function located in another file (flasher01.c) that adds two integers and a constant which is defined in the header file (flasher01.h) and then outputs the result.

[me@myplace]$ cat main01.c
/* main01.c
testing multi modules */

#include <stdio.h>
#include "flasher01.h"

int main (void)
{
int a = 3, b=4, c;
c = adder(a,b);
printf ("%d%c", c, '\n');
}

[me@myplace]$ cat flasher01.c
/* flasher01.c
muulti module test */

#include "flasher01.h"

int adder (int int1, int int2)
{
return int1 + int2 + CONSTANT;
}

[me@myplace]$ cat flasher01.h
/* flasher01.h
testing multi modules */

#define CONSTANT 22
int adder (int int1, int int2)

[me@myplace]$ gcc main01.c flasher01.c flasher01.h -o mainApp
main01.c: In function `adder':
main01.c:11: error: parse error before '{' token
main01.c:10: error: parm types given both in parmlist and separately
flasher01.c: In function `adder':
flasher01.c:10: error: parse error before '{' token
flasher01.c:9: error: parm types given both in parmlist and separately
gcc: compilation of header file requested
[me@myplace]$

main01.c:11: error: parse error before '{' token
main01.c:10: error: parm types given both in parmlist and separately

There is no need for "void" in main. If you don't need any arguments, just make main:

main() {}

not:

main(void) {}

And to slightly improve your code:

/* main01.c
testing multi modules */

#include "flasher01.h"

int main()
{
     int a = 3, b = 4;
     printf ("%d\n", adder(a, b));
}

I got rid of stdio.h, because I #included it in flasher01.h:

/* flasher01.h
testing multi modules */

#include <stdio.h>

#define CONSTANT 22
int adder (int int1, int int2); /* you forgot a semi-colon */

You also do not need a, b, or c. I kept a and b, because they seemed more necessary then c. I just printed the return value of adder(), instead of putting the return value of adder into a seperate variable, and then printing it. This only saves a small amount of memory, but it still helps improve the program. If you wanted to save even more, don't even define a and b. Just make adder():

adder(3, 4);

Your are missing a trailing semicolon in the adder prototype.

Thanks very much. One question, does main() have to have a return type?
I now have
int main()
could this just have easily been
void main()
?
I think this is what I originally intended.

Yes. void means doesn't have a return value. But you don't need int in front of main(), because functions in C (and main() is a function), are expected to return int by defualt.

main()
{
}

is the same as

int main()
{
}

main does return an int as used directly in a call to "exit". This is the return value that a program returns to the parent program via wait/waitpid.

If you are using GCC try with -Wall -Werror, it will alert you to many common errors.

Thanks again. Further to this, why is "void" used as a parameter in a function that takes no arguments, i.e.
int main (void)

I see this a bit in C (I started out learning C++) , why not just use

int main()
?

Is main a special case, or do you always use void in this way in a function that takes no arguments?

Which of the following is correct in C?
myFunction(void)
OR
myFunction()
?

There is no need to put void as function arguements, but people do it anyway, probaly for clarifacation when others read their code. But remember that function(void) isn't required, but void function() is. The latter means a function without a return value.

Not necessarily so...

In ANSI C, the following happens...

  1. if the return type is empty it is considered an 'int'.

  2. if the function has a void or a list of arguments those are the arguments that the compiler will check against.

  3. if the argument list is empty it is effectively saying "I don't know what the arguments are" and you can call it with any arguments you like and may only get a warning. It is equivalent of ellipses, (...)

int myx()
{
	return 0;
}

int myz(void)
{
	return 0;
}

void myy()
{
	myx();
	myx(2);
	myx(3);
	myz();
	myz(1);
}

There may only be a warning only for the "myz(1)".

Thanks a lot. I am a beginner as you can see. I am transitioning from fundamental C++ to fundamental C.