Problem with function which reutrns pointer to a value

i have a function:
char *pcCityIdToCountryName(ADMIN_DB_DATA *pstHEader, unit uiCityID)

this returns a pointer to CountryName if cityId is given.
to retrieve countryname i give:

char *CountryName;
CountryName = pcCityIdToCountryName(..................);

but when i compile it is giving :
Unresolved
pcCityIdToCountryName

Iam new to C programming. Please help

The compiler (actually the linker) is telling you that it can't find the

char *pcCityIdToCountryName(ADMIN_DB_DATA *pstHEader, unit uiCityID)

code anywhere. Is this function in another module? If so you will have to link against that module.

cc myfile.c -o myfile -L<some shared library>
or
cc myfile.c somemodule.o -o myfile

The -L syntax requires you to remove the "lib" from in front of the shared library name:

libcountry.so

becomes:
-L country

The .so or .sl is not needed.

Thankx for the reply!
As u have said the function is in another file called admin.c, but everything is included in Make file.....
:confused: is the statement i have written correct....
does Unresolved means an error... or can it be ignored?????

unresolved = fatal error

unresolved means the linker could not find it. The program must have it. The program will not run without it.

Thank u. I got the solution. :slight_smile:

Your other post implies you may be passing back a string.

You may prefer to use strcpy like so:

char CountryName[XX*];

strcpy(CountryName, pcCityIdToCountryName(..................) );

*where XX is the size of the string.

The reason being is that you don't know if the char pointer being passed back is still pointing to an allocated memory block. Sometimes I have seen functions pass back a pointer to a local variable or memory being allocated and then made free. It just so happens that you are pointing to a memory location that still has a string (null terminated) value. This may not be the case later on in the program's execution, especially when you are allocating and freeing memory frequently, and you may encounter a memory violation.

At least by copying string into a local variable you can protect against any future problems.

Of course, if it is your own function, you can make your own judgements as to the best way to call it, based on your overall design.