Thread: Pointers Between Functions

  1. #1
    Registered User
    Join Date
    Feb 2003

    Question Pointers Between Functions


    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.

  2. #2
    Join Date
    Aug 2001
    Groningen (NL)

    > PUBLIC char* JRRreadRecord()

    means that you need to return a pointer to char. There fore this

    > return pResult;

    is correct.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Conversion of pointers to functions
    By hzmonte in forum C Programming
    Replies: 0
    Last Post: 01-20-2009, 01:56 AM
    By cjohnson412 in forum C++ Programming
    Replies: 4
    Last Post: 08-11-2008, 10:48 PM
  3. Replies: 4
    Last Post: 11-23-2003, 07:15 AM
  4. pointers, functions, parameters
    By sballew in forum C Programming
    Replies: 3
    Last Post: 11-11-2001, 10:33 PM