Atoi & Itoa

This is a discussion on Atoi & Itoa within the C Programming forums, part of the General Programming Boards category; Does any one know what this functions stands for-' and what does it do? thanks...

  1. #1
    Unregistered
    Guest

    Question Atoi & Itoa

    Does any one know what this functions stands for-' and what does it do?
    thanks

  2. #2
    Registered User
    Join Date
    Mar 2002
    Posts
    95
    atoi converts a string to an integer, put a strings pointer and it returns an int:
    Declaration: int atoi(const char *s);

    itoa convets an integer to a string:
    Declaration:
    _ char *itoa(int value, char *string, int radix);
    _ char *ltoa(long value, char *string, int radix);
    _ char *ultoa(unsigned long value, char *string, int radix);

  3. #3
    Me want cookie! Monster's Avatar
    Join Date
    Dec 2001
    Posts
    680
    Code:
    #include <stdlib.h>
    #include <string.h>
    
    int main()
    {
      int i = 22;
      char buf[20];
    
      printf("itoa %d (binary)  = %s\n", i, itoa(i, buf, 2));
      printf("itoa %d (octal)   = %s\n", i, itoa(i, buf, 8));
      printf("itoa %d (decimal) = %s\n", i, itoa(i, buf, 10));
      printf("itoa %d (hex)     = %s\n", i, itoa(i, buf, 16));
    
      strcpy(buf, "05");
      printf("\natoi %s           = %d\n", buf, atoi(buf));
    
      return 0;
    }

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Having trouble with atoi
    By NewbGuy in forum C Programming
    Replies: 2
    Last Post: 05-22-2009, 11:55 PM
  2. Problem with atoi and itoa
    By jdmarsh2005 in forum C Programming
    Replies: 3
    Last Post: 03-11-2009, 12:19 PM
  3. Really Weird itoa Problem
    By Grantyt3 in forum C++ Programming
    Replies: 8
    Last Post: 12-19-2005, 11:44 PM
  4. Problem with atoi in C
    By garagebrian in forum C Programming
    Replies: 5
    Last Post: 08-24-2004, 01:59 PM
  5. string to int conversion not using atoi()
    By linucksrox in forum C Programming
    Replies: 2
    Last Post: 05-19-2004, 12:17 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21