Hi
A bit new to C and struggling with passing a pointer back to a calling function. Read the manual but not sure what I am doing wrong..
Basically I have a function (JRRreadRecord) which reads a record from a file (among other things). I want this to return the result to pRecord in the main call. I know that the result returned by the readFile function will either be a pointer to the record or NULL if no record is found.
This is core dumping on the line that starts char *pRecord in the main function. I was wondering if I should be passing the value back using an int memory address rather than a char*?
Code is...
public main()
{
.....
/* go read a record from the file in function JRRreadRecord */
char *pRecord = JRRreadRecord();
while ( pRecord != NULL) {
process the file in here
}
....
}
PUBLIC char* JRRreadRecord()
{
/* read a single record from the file. The readFile function returns a Pointer to record or NULL if no record found.*/
char *pResult = readFile(fileName);
/* The question is do we return the record or do we return the memory address? like this.. */
return pResult
}
Thanks in advance for any help.