#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2013
    Posts
    1
    Rep Power
    0

    HELP ME SOLVE a cahllenge need help please!!!


    /*
    * GUIDELINES:
    * - Look at main(): it calls various functions.
    * - You are asked to implement two functions: str_cpy() and str_cat().
    * - Reading main() carefully will allow to understand str_cpy() and str_cat()
    * signature and usage.
    * - The code you write needs to be "library quality"; as good as you would
    * expect a good libc to implement such functions.
    * - At the top of the page, you see 4 includes - indicating the functions that
    * can be used to implement str_cpy() and str_cat().
    *
    * FYI: it is possible to implement str_cpy() and str_cat() efficiently in no
    * more than 7 lines of code per function, and in less than 5 minutes.
    *
    * Good luck!
    */
    #include <stdio.h>
    #include <stdlib.h>
    #include <string.h>
    #include <stdarg.h>

    int main(int argc, char *argv[])
    {
    char *s = NULL;
    str_cpy(&s, "Hola Hola");
    str_cpy(&s, s+5);
    str_cat(&s, " Mundo");
    puts(s); /* result: "Hola Mundo!" */
    return 0;
    }
  2. #2
  3. Contributing User
    Devshed Supreme Being (6500+ posts)

    Join Date
    Jan 2003
    Location
    USA
    Posts
    7,145
    Rep Power
    2222
    Do you have a question? What is it?

    If you have a problem, then what is it? Be sure to show your code.
  4. #3
  5. Contributing User
    Devshed Demi-God (4500 - 4999 posts)

    Join Date
    Aug 2011
    Posts
    4,837
    Rep Power
    480
    Tell your instructor the provided framework has a terrible flaw. First, find the problem so you can answer correctly when asked.

    Comments on this post

    • jwdonahue agrees : The instructor is an idiot. Oh! Does that give it away?
    [code]Code tags[/code] are essential for python code and Makefiles!
  6. #4
  7. Contributed User
    Devshed Specialist (4000 - 4499 posts)

    Join Date
    Jun 2005
    Posts
    4,379
    Rep Power
    1871
    Are you trying to get a job?

    > * FYI: it is possible to implement str_cpy() and str_cat() efficiently in no
    > * more than 7 lines of code per function, and in less than 5 minutes.
    Maybe so, but no sane person would ever claim "library quality" after 5 minutes of hacking code.

    7 lines is probably enough to implement the raw functionality.
    I doubt it would be enough to also implement all the error checking and edge cases.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper
  8. #5
  9. Contributing User
    Devshed Demi-God (4500 - 4999 posts)

    Join Date
    Aug 2011
    Posts
    4,837
    Rep Power
    480
    If I were writing "library quality" I would struggle to find a way to make some part of the code move words instead of bytes!
    [code]Code tags[/code] are essential for python code and Makefiles!

IMN logo majestic logo threadwatch logo seochat tools logo