problem with atoi ()

Discussion in 'C++' started by meyup, Jun 21, 2010.

  1. meyup

    meyup New Member

    Joined:
    Feb 15, 2010
    Messages:
    102
    Likes Received:
    0
    Trophy Points:
    0
    Hi,

    I have a problem with atoi ()
    My code is as follows:
    Code:
    # Include <stdlib.h> 
    # Include <stdio.h> 
    int main (void) ( 
        char* x = "f"; 
        int command; 
        command = atoi (x); 
        printf ("number:% d", command); 
       return 0; 
    )
    How to remove the link, atoi () returns 0 if could not be converted to char. with me, the program always 0 Why?
     
  2. techme

    techme New Member

    Joined:
    Feb 15, 2010
    Messages:
    86
    Likes Received:
    0
    Trophy Points:
    0
    because "f" is not a number. as simple as that
     
  3. creative

    creative New Member

    Joined:
    Feb 15, 2010
    Messages:
    87
    Likes Received:
    0
    Trophy Points:
    0
    what is a number "f" be? 1? 3? 19?
    if you work instead of "f" as "650" uses it.

    btw:
    printf is not c, cpp court and in 'real'?
     
  4. meyup

    meyup New Member

    Joined:
    Feb 15, 2010
    Messages:
    102
    Likes Received:
    0
    Trophy Points:
    0
    I probably hit the wrong function. in reality I would like to determine the ANSI code given by a letter that is then returned. I found the function in CharToInt R.oo, but I'd like something not so large scale. Is there something?
     
  5. inspiration

    inspiration New Member

    Joined:
    Feb 15, 2010
    Messages:
    85
    Likes Received:
    0
    Trophy Points:
    0
    What do you want exactly? What number should I get out at "f"?
     
  6. meyup

    meyup New Member

    Joined:
    Feb 15, 2010
    Messages:
    102
    Likes Received:
    0
    Trophy Points:
    0
    The ANSI code in which case, 69 decimal or 45 hex
     
  7. inspiration

    inspiration New Member

    Joined:
    Feb 15, 2010
    Messages:
    85
    Likes Received:
    0
    Trophy Points:
    0
    you can use
    Code:
    printf ("Number:% d", 'f');
     
  8. meyup

    meyup New Member

    Joined:
    Feb 15, 2010
    Messages:
    102
    Likes Received:
    0
    Trophy Points:
    0
    Thank you. But why, I tap in the dark and always think so complicated and it is so easy.
     
  9. meyup

    meyup New Member

    Joined:
    Feb 15, 2010
    Messages:
    102
    Likes Received:
    0
    Trophy Points:
    0
    since you are indeed benefit:

    why does it not here?

    Code:
    char* book = "x"; 
    int test = (int) book;     
    court <<"number: "<<test <<endl;
    It always returns 4,198,960th Why?
     
  10. pankaj.sea

    pankaj.sea New Member

    Joined:
    Apr 6, 2009
    Messages:
    461
    Likes Received:
    13
    Trophy Points:
    0
    Occupation:
    Web Developer
    Location:
    Kolkata
    Home Page:
    http://ipankaj.net
    that is the memory address of the chars
     
  11. techme

    techme New Member

    Joined:
    Feb 15, 2010
    Messages:
    86
    Likes Received:
    0
    Trophy Points:
    0
    nt test = (int) * book;
     
  12. meyup

    meyup New Member

    Joined:
    Feb 15, 2010
    Messages:
    102
    Likes Received:
    0
    Trophy Points:
    0
    I am now somewhat confused. of course it must be int (* char be). Thank you

    Does all the other way around? So in some book = char (test)? So it is not hot but how do this so that it's going?
     
  13. techme

    techme New Member

    Joined:
    Feb 15, 2010
    Messages:
    86
    Likes Received:
    0
    Trophy Points:
    0
    Code:
    int test = 120; 
    char book = test;
    use it.
     
  14. NewsBot

    NewsBot New Member

    Joined:
    Dec 2, 2008
    Messages:
    1,267
    Likes Received:
    2
    Trophy Points:
    0
    I am not sure if you have your answer or not but the function you are using takes character and not string.
     

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