Thread: basic questions about C

  1. #1
    Registered User
    Join Date
    Jan 2008
    Posts
    569

    basic questions about C

    1. how does the strcat () method actually works in the library?
    does it just find where the '\0' location of the string that needs to be concatenated and
    take that as the starting index to concatenate with the other string??
    2. can someone write me the function atof & sprintf?

  2. #2
    Dr Dipshi++ mike_g's Avatar
    Join Date
    Oct 2006
    Location
    On me hyperplane
    Posts
    1,218
    1. how does the strcat () method actually works in the library?
    does it just find where the '\0' location of the string that needs to be concatenated and
    take that as the starting index to concatenate with the other string??
    Yeah pretty much.
    2. can someone write me the function atof?
    No.

  3. #3
    Registered User
    Join Date
    Jan 2008
    Posts
    569
    does the atof actually just use strtol()?

  4. #4
    Dr Dipshi++ mike_g's Avatar
    Join Date
    Oct 2006
    Location
    On me hyperplane
    Posts
    1,218
    Do you mean strtod? And no I imagine it does not. But it would make a nice cheeky solution for an assignment.

    I made a function once to convert from float to string as I couldent seem to find one in the standard libraries. But in your case why not just use existing functions?

  5. #5
    uint64_t...think positive xuftugulus's Avatar
    Join Date
    Feb 2008
    Location
    Pacem
    Posts
    355
    Actually if you are on a *nix system, the entire C library source should be available or installable if curiosity is your motive.
    Code:
    ...
        goto johny_walker_red_label;
    johny_walker_blue_label: exit(-149$);
    johny_walker_red_label : exit( -22$);
    A typical example of ...cheap programming practices.

  6. #6
    Registered User
    Join Date
    Jan 2008
    Posts
    569
    this is not for an assignment, I am studying for a test to tomorrow

  7. #7
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Writing your own atof() wold be a few dozen lines of code at the very least [unless you want to do it in the obfuscated way].

    The principle is, in pseudo-code:
    Code:
    recognize sign, save it away. move to next char if there is a sign.
    while(isdigit(ch)) result = result * 10 + ch-'0'. move to next char
    if (ch == '.') next char; result += do_decimals();
    if (tolower(ch) == 'e') next char; result *= do_exponent();
    multiply in sign.
    
    do_decimals()
    {
        result = 0;
        mul = 0.1;
        while(isdigit(ch)) result += (ch-'0') * mul; mul /= 10.0; next ch;
        return result;
    }
    
    do_exponent()
    {
        get sign and remember
        while(isdigit(ch)) result = result * 10 + (ch-'0'); next char;
        return exp(sign * result * ln(10));
    }
    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Basic Questions
    By Panda_ in forum C Programming
    Replies: 15
    Last Post: 09-23-2009, 04:24 PM
  2. questions....so many questions about random numbers....
    By face_master in forum C++ Programming
    Replies: 2
    Last Post: 07-30-2009, 08:47 AM
  3. Some Basic questions
    By BlaX in forum C Programming
    Replies: 7
    Last Post: 06-30-2009, 09:51 AM
  4. Please help, basic unsigned conversion questions
    By ninjacookies in forum C Programming
    Replies: 3
    Last Post: 04-20-2005, 10:50 AM
  5. questions questions questions.....
    By mfc2themax in forum A Brief History of Cprogramming.com
    Replies: 1
    Last Post: 08-14-2001, 07:22 AM