help please

Discussion in 'C Programming' started by chump1708@yahoo.com, Dec 12, 2005.

  1. Guest

    line 50 - char *b, q, *r;

    line 200 - b = getbuf ();

    Line 201 q = *b;

    Line 212 R = anotherfunction (b);

    Lines 213-2003 /* we want to use 'q' and 'r' here */

    Line2000 char * getbuf ()

    Line2001 {
    Line 2002 char buff [8];

    Lines 2003-2050 /* unspecified buff defined here */

    Line 2051 return (char*) buff;

    Line 2052 }



    1. What will be in variable 'q' after line 201 is executed?
    Under what conditions might this not be so?



    2. Is there an alternative, but equivalent, way to write line
    2000? If so, what is it?



    3. Is getbuf() a reasonable function?



    4. Will getbuf() execute at all?



    5. Please comment on line 2051.



    6. Is getbuf() good practice, and why?



    7. What line not given should be provided for compilation?



    8. How, exactly, could one get a second 'char*' to use back from
    this function? Be specific in terms of the exact syntax needed. (That
    is, provide code.) Another way to state this question is how can this
    function be modified to return a 'char*' (that is, it maintains the
    same return type) from the function, and an additional 'char *'
    value in one function call. Please make sure that your answer will work
    even if the size of the char * desired is not known in the outside
    calling function. Avoid (do no use) C++ syntax. Include statement in
    called and calling functions. Use good programming practice.

    9. What's the difference between system calls and library functions?
    , Dec 12, 2005
    #1
    1. Advertising

  2. Guest

    Can anyone suggest me a good link for pointers and memmory management??
    Thanks
    , Dec 12, 2005
    #2
    1. Advertising

  3. Eric Sosman Guest

    wrote:

    > [homework questions]


    A good many of these are covered in the comp.lang.c
    Frequently Asked Questions (FAQ) list at

    http://www.eskimo.com/~scs/C-faq/top.html

    Begin your studies there.

    --
    Eric Sosman
    lid
    Eric Sosman, Dec 12, 2005
    #3
  4. "" <> writes:
    [...]
    > 1. What will be in variable 'q' after line 201 is executed?
    > Under what conditions might this not be so?
    >
    > 2. Is there an alternative, but equivalent, way to write line
    > 2000? If so, what is it?
    >
    > 3. Is getbuf() a reasonable function?
    >
    > 4. Will getbuf() execute at all?
    >
    > 5. Please comment on line 2051.

    [snip]

    I'll give you the standard response: give us your instructor's e-mail
    address so we can submit the answers directly.

    --
    Keith Thompson (The_Other_Keith) <http://www.ghoti.net/~kst>
    San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
    We must do something. This is something. Therefore, we must do this.
    Keith Thompson, Dec 12, 2005
    #4
  5. "" wrote:
    >
    > line 50 - char *b, q, *r;
    >
    > line 200 - b = getbuf ();

    [...]
    > Line 2051 return (char*) buff;
    >
    > Line 2052 }
    >
    > 1. What will be in variable 'q' after line 201 is executed?
    > Under what conditions might this not be so?

    [...]
    > 9. What's the difference between system calls and library functions?


    This exact message was posted, verbatim, back on Oct. 3, under the
    subject "C question - Know the answers to the following".

    So, either this is a serial drive-by troll, or the result of someone
    supposedly teaching C to clueless newbies.

    --
    +-------------------------+--------------------+-----------------------------+
    | Kenneth J. Brody | www.hvcomputer.com | |
    | kenbrody/at\spamcop.net | www.fptech.com | #include <std_disclaimer.h> |
    +-------------------------+--------------------+-----------------------------+
    Don't e-mail me at: <mailto:>
    Kenneth Brody, Dec 12, 2005
    #5
  6. osmium Guest

    <> wrote:

    > line 50 - char *b, q, *r;
    >
    > line 200 - b = getbuf ();
    >
    > Line 201 q = *b;
    >
    > Line 212 R = anotherfunction (b);
    >
    > Lines 213-2003 /* we want to use 'q' and 'r' here */
    >
    > Line2000 char * getbuf ()
    >
    > Line2001 {
    > Line 2002 char buff [8];
    >
    > Lines 2003-2050 /* unspecified buff defined here */
    >
    > Line 2051 return (char*) buff;


    You are returning a pointer to an auto array. This is really bad because
    it might work, by chance, from time to time. The quick fix is to change
    line 2002 to:

    static char buff[8];

    The proper fix usually is to change the ownership of the array to a higher
    level (outer) function.

    Why did you provide a (char*) cast on the return statement? Did it fail to
    compile without the cast?

    Your post is too cryptic to my taste and you try to get *way* too much
    information from a single post.

    >
    > Line 2052 }
    >
    >
    >
    > 1. What will be in variable 'q' after line 201 is executed?
    > Under what conditions might this not be so?
    >
    >
    >
    > 2. Is there an alternative, but equivalent, way to write line
    > 2000? If so, what is it?
    >
    >
    >
    > 3. Is getbuf() a reasonable function?


    <snip questions 4, 5, 6, 7, 8 and 9>
    osmium, Dec 12, 2005
    #6
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. JC
    Replies:
    4
    Views:
    7,952
    Jeff C
    Jul 8, 2004
  2. Replies:
    4
    Views:
    492
    Chris Uppal
    May 5, 2005
  3. KK
    Replies:
    2
    Views:
    528
    Big Brian
    Oct 14, 2003
  4. MuZZy
    Replies:
    7
    Views:
    1,723
    Mike Hewson
    Jan 7, 2005
  5. mera
    Replies:
    7
    Views:
    1,081
Loading...

Share This Page