Thread: char to int

  1. #1
    Unregistered
    Guest

    char to int

    Hi,
    Can any one please tell me what is the best way to convert a char to an int. I can not seem to find any build in function to do the job. Thanks in advance.

  2. #2
    Used Registerer jdinger's Avatar
    Join Date
    Feb 2002
    Posts
    1,065

    char to int

    Use atoi() from <stdlib.h>.

    char Words[]="123";
    int Number;
    Number = atoi(Words);

    Jason

  3. #3
    Registered User
    Join Date
    Mar 2002
    Posts
    203
    atoi() will return 0 if any character is not a digit

  4. #4
    Unregistered
    Guest
    for a single char you can do it like this:

    char letter = 'a';
    int number = (int)letter;

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 48
    Last Post: 09-26-2008, 03:45 AM
  2. can some one please tell me the cause of the error ?
    By broli86 in forum C Programming
    Replies: 8
    Last Post: 06-26-2008, 08:36 PM
  3. Replies: 14
    Last Post: 06-28-2006, 01:58 AM
  4. Game Won't Compile
    By jothesmo in forum C++ Programming
    Replies: 2
    Last Post: 04-01-2006, 04:24 PM
  5. Contest Results - May 27, 2002
    By ygfperson in forum A Brief History of Cprogramming.com
    Replies: 18
    Last Post: 06-18-2002, 01:27 PM