C Questions

Discussion in 'C' started by am2007, Sep 30, 2007.

Thread Status:
Not open for further replies.
  1. am2007

    am2007 New Member

    Joined:
    Sep 30, 2007
    Messages:
    3
    Likes Received:
    0
    Trophy Points:
    0
    Can anyone help me with the following?:

    Correct the problems with this function, and then extend it so that it also returns a usable array of pointers to some structures.

    The extended version of this function should:

    a) Maintain the same "char *" return type which returns a pointer to a usable, for storing a ā€œCā€ string, memory buffer.

    b) In addition, also return a usable array of pointers to structures. This array of pointers is of variable and random length, which must be obtained using GetNumberOfSomeSeqsToGenerate(), which is called, ONLY, from within this new extended version of the function.

    c) The type of these structures and the function that should be used to get these structures are defined as follows:

    typedef struct {
    char* name; /* '\0'-terminated C string */
    int number;
    } SomeSeq;


    /* How many structures should be in the returned array
    */
    int GetNumberOfSomeSeqsToGenerate(void);

    /* Return the next structure (to fill the
    * abovementioned array with).
    * Caller is responsible for the cleanup of the returned structure
    * and all its content. The latter are all allocated in
    * dynamic memory.
    */
    SomeSeq * GetNextSomeSeq(void);

    Do NOT(!) use "C++" syntax.
    Use good programming practice, as much as these instructions allow.


    Write a function which calls this function, prints out all data returned by it, and makes sure there are no memory leaks.

    Do NOT(!) use "C++" syntax.
    Use good programming practice, as much as these instructions allow.
     
  2. DaWei

    DaWei New Member

    Joined:
    Dec 6, 2006
    Messages:
    835
    Likes Received:
    5
    Trophy Points:
    0
    Occupation:
    Semi-retired EE
    Location:
    Texan now in Central NY
    Home Page:
    http://www.daweidesigns.com
    Duplicate question. Thread closed.
     
  3. shabbir

    shabbir Administrator Staff Member

    Joined:
    Jul 12, 2004
    Messages:
    15,375
    Likes Received:
    388
    Trophy Points:
    83
Thread Status:
Not open for further replies.

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice