THIS IS MY Job Interview--can some1 help me solve it???

Discussion in 'C' started by cdev, Aug 7, 2012.

  1. cdev

    cdev New Member

    Joined:
    Aug 6, 2012
    Messages:
    1
    Likes Received:
    0
    Trophy Points:
    0
    * GUIDELINES:
    * - Look at main(): it calls various functions.
    * - You are asked to implement two functions: str_cpy() and str_cat(). No need
    * to implement str_printf() and str_free()
    * - 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().
    * - You have 15 minutes to implement the whole solution.
    *
    * 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.
    *
    */
    Code:
    #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");
        str_printf(&s, "%s!", s);
        puts(s); /* result: "Hola Mundo!" */
        str_free(&s);
        return 0;
    }
     
    Last edited by a moderator: Aug 7, 2012
  2. xpi0t0s

    xpi0t0s Mentor

    Joined:
    Aug 6, 2004
    Messages:
    3,009
    Likes Received:
    203
    Trophy Points:
    63
    Occupation:
    Senior Support Engineer
    Location:
    England
    I'm pretty sure I could do it, but isn't the point that YOU do it? After all, if you get the job, you can't be posting to Go4Expert "This is my job for today, can someone help me with it?" Or are you planning also to post "This is my salary, can someone help me spend it?"
     

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