i dont know C, but, i dont think you can declare a function inside of another, ie:
Code:
#include <stdio.h>
int main()
{
int some_func()
{
return 1;
}
}
if you put the function AFTER main() then you must have a function prototype (before main) for it so the compiler knows what the function is when it gets called, ie:
Code:
#include <stdio.h>
int some_func(); // <-- this is a 'prototype', telling the compiler
// that this function exist, what its expected parameters are (none)
// and its return type (int) so it knows if a compile-time error occurs
// ie, if the function was called as: some_func(1);
// ^
int main()
{
return some_func();
}
int some_func() //function implementation (body/details)
{
return 1;
}
remember the file is processed sequentially so a program like this wont work (because the compiler wont know the some_func() function exist (because, sequentially, it hasnt been defined yet):
Code:
#include <stdio.h>
int main()
{
return some_func();
}
int some_func()
{
return 1;
}
or you can simply declare the function instead of doing the prototype before main, as in:
Code:
#include <stdio.h>
int some_func()
{
return 1;
}
int main()
{
return some_func();
}
i dont know 100% but i think the purpose of function prototyping is so that other programmers reading your code will be able to (quickly, easily) see each function you create, their return type, parameters/signature, and name. they wont have to scroll through the file to see the implementation (body) of the function.. it might be useful to comment each function at the top next to the prototype to make things even more clear, ie:
Code:
#include <stdio.h>
int some_func();
/*
some_func() - example function that does fun stuff etc
parameters - none
return type - int -- explain what each return value means to the program/mer
*/
int main()
{
return some_func();
}
int some_func()
{
return 1;
}
sorry for lengthy reply for a simple question.. got carried away. hope it helps