After two years of C#, I tried C and i have some "noob" errors.
I tried to reverse an array with recursion, and i have this error:
error C3861: 'Rekurzija' indentifer not found
this is my code:
#include "stdafx.h"
#include "stdio.h"
int main()
{
int niz[] = {1,2,3,4,5,6};
int duzina = sizeof(niz)/sizeof(int);
printf("%s",niz[Rekurzija(duzina)]);
getchar();
}
int Rekurzija(int niz)
{
int i = sizeof(niz)/sizeof(int);
while(i!=0)
return Rekurzija(i-1);
}
In C, everything must be declared before being used. So you must add a declaration for Rekurzija before main:
int Rekurzija(int);
This just tells the compiler that when it sees the Rekurzija call later, that is a function call taking an int and returning an int. That is all it needs to handle the call, the definition can be somewhere else, such below main in your case, or even in another file, as is very common (delcaration in a .h file, and definition in a .c file).
In C you should have the function prototype listed before the function that calls it.
So you should add the following after your includes:
int Rekurzija(int niz);
Notice that without having a prototype, things still might work; the compiler will make a guess for the prototype but problems will arise if the guess is different than what your function really is.
In C, you have to declare entities before you reference them.
You need to add:
int Rekurzija(int niz);
to tell the compiler that Rekurzija exists, and what kind of properties it has (e.g., it is a function with int argument and result) as a "forward" declaration preceding your main function.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With