convert char to int

when i use atoi, i get
implicit declaration of function `int atoi(...)'
--> 25: NP=atoi(readin[0]);
is there any other way to convert char to int?

Comments

  • : implicit declaration of function `int atoi(...)'
    : --> 25: NP=atoi(readin[0]);

    The function is defined like so:

    int atoi(const char *string);

    So, make sure you are passing it a pointer to a character array that ends with a NULL char (i.e. a string). I have no idea what readin[0] is, but if readin is a string, then you are passing it a single character, not a string.
    Jason Doucette
    http://www.jasondoucette.com/
    "[italic]If you don't win, its not a great tragedy - the worst that happens is that you lose a game.[/italic]" - [italic]Bobby Fischer[/italic]

  • : when i use atoi, i get
    : implicit declaration of function `int atoi(...)'
    : --> 25: NP=atoi(readin[0]);
    : is there any other way to convert char to int?
    :

    Make sure you include right libraries?
    #include
    [italic][blue]To understand recursive, first you need to understand recursive[/blue][/italic]

  • : : when i use atoi, i get
    : : implicit declaration of function `int atoi(...)'
    : : --> 25: NP=atoi(readin[0]);
    : : is there any other way to convert char to int?
    : :
    :
    : Make sure you include right libraries?
    : #include
    : [italic][blue]To understand recursive, first you need to understand recursive[/blue][/italic]
    :
    :
    [green]If you really want to convert a char to an int then atoi() is the wrong way. That takes a character [b]string[/b] such as "1234" and returns the int. To change a char to an int is easily done by a cast.
    [code]
    int Integer;
    char Character;
    ...
    Integer = (int)Character;
    [/code]

  • : [green]If you really want to convert a char to an int then atoi() is the wrong way. That takes a character [b]string[/b] such as "1234" and returns the int. To change a char to an int is easily done by a cast.
    : [code]
    : int Integer;
    : char Character;
    : ...
    : Integer = (int)Character;
    : [/code]
    :
    :

    [blue]Well, maybe. You're right if all you want to do is to convert a char to int with the same hex value, e.g. 'A' = 64. but if you want to convert '1' to its numeric value 1, then you need to do a little more.[/blue]
    [code]
    int Integer;
    char Character = '1';

    Integer = (int)Character[red] - '0';[/red]
    [/code]

  • : : [green]If you really want to convert a char to an int then atoi() is the wrong way. That takes a character [b]string[/b] such as "1234" and returns the int. To change a char to an int is easily done by a cast.
    : : [code]
    : : int Integer;
    : : char Character;
    : : ...
    : : Integer = (int)Character;
    : : [/code]
    : :
    : :
    :
    : [blue]Well, maybe. You're right if all you want to do is to convert a char to int with the same hex value, e.g. 'A' = 64. but if you want to convert '1' to its numeric value 1, then you need to do a little more.[/blue]
    : [code]
    : int Integer;
    : char Character = '1';
    :
    : Integer = (int)Character[red] - '0';[/red]
    : [/code]
    :
    [green]Yes indeed.[/green]

  • : : : [green]If you really want to convert a char to an int then atoi() is the wrong way. That takes a character [b]string[/b] such as "1234" and returns the int. To change a char to an int is easily done by a cast.
    : : : [code]
    : : : int Integer;
    : : : char Character;
    : : : ...
    : : : Integer = (int)Character;
    : : : [/code]
    : : :
    : : :
    : :
    : : [blue]Well, maybe. You're right if all you want to do is to convert a char to int with the same hex value, e.g. 'A' = 64. but if you want to convert '1' to its numeric value 1, then you need to do a little more.[/blue]
    : : [code]
    : : int Integer;
    : : char Character = '1';
    : :
    : : Integer = (int)Character[red] - '0';[/red]
    : : [/code]
    : :
    : [green]Yes indeed.[/green]
    :
    :
    WOW!
    Thank you SO MUCH for this info!
    You've just solved a homework problem for me! I've already put in too
    much time on this, but now I can finish my code.
    Thanks again!
    Take care;
    Dan
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories