Identifier not found?

DocNet picture DocNet · Oct 29, 2012 · Viewed 7.6k times · Source

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);
}

Answer

amaurea picture amaurea · Oct 29, 2012

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).