Results 1 to 6 of 6

Thread: The atoi() function of the C++

  1. #1
    Join Date
    Jan 2010
    Posts
    26

    The atoi() function of the C++

    Hi, All. I am the student of the IT. I can have the good knowledge of the programming languages not all of the languages but some of them. I can also like to do the programming. But I can not heard about the atoi() function of the C++ language. So, I want to know about the atoi() function of the C++ language. And how can I use this function in the coding of the C++ language. Reply me if you can have the answer for me.

  2. #2
    Join Date
    Jan 2008
    Posts
    1,521

    The atoi() function

    The atoi() function can be used in the C++ language to transform the string into an integer. The atoi() function can be the member of the cstdlib header files of the C++ language library. The atoi() function can parses the C++ string by translating its content as an integer number which can be returned as an int value. The following can be the syntax of the atoi() function in the C++ language :
    Code:
    int atoi ( const char * sr );
    Last edited by Modifier; 27-02-2010 at 04:56 PM.

  3. #3
    Join Date
    May 2008
    Posts
    2,389

    The atoi()

    This program can states you or guides you how to use and how to implement the atoi() function in the programming of the C++ language as follows :
    Code:
    #include <stdio.h>
    #include <stdlib.h>
    int main ()
    {
      int j;
      char sInpt [256];
      printf ("Enter a number: ");
      fgets ( sInpt, 256, sdn );
      j = atoi (sInpt);
      printf ("The value entered is %d. The double is %d.\n",j,j*2);
      return 0;
    }
    Output:
    Code:
    Enter a number: 73
    The value entered is 73. The double is 146.

  4. #4
    Join Date
    Oct 2005
    Posts
    2,393

    Re: The atoi() function of the C++

    Hi, according to me the atoi() function can an accepts a string and then can transforms that string into an integer type. For an example : If "5678" can be passed to the atoi() function then the atoi() function can returns the 5678 as an integer. If the string can contains a decimal value then the number that could be truncated. i.e., "401.31" could be returned as 401 and excludes the numbers that can be after the decimal places.

  5. #5
    Join Date
    Nov 2005
    Posts
    1,323

    The atoi() function of the C++

    The atoi() function can returns the integer value if there can be success and the atoi() function can returns the zero value if there can be a failure. If the resultant value can be the out of range of the atoi() function then it can returns the maximum or minimum integer value. The following can be the syntax of the atoi() function of the C++ language :
    1. str : This parameter can contains the cstring that can be starting with the representation of an integer value or number.

  6. #6
    Join Date
    Feb 2008
    Posts
    1,852

    Re: The atoi() function of the C++

    PROGRAM :
    Code:
       #include <stdlib.h>
        #include <stdio.h>
        int main(void)
        {
          char *str = "123456";
          int n = atoi(str);
          printf("The string %s as an integer is = %d\n",str,n);
          char *str2 = "314hello";
          n = atoi(str2);
          printf("The string %s as an integer is = %d\n",str2,n);
          return 0;
        }
    Output :
    Code:
        The string 123456 as an integer is = 123456
        The string 314hello as an integer is = 314

Similar Threads

  1. c++ equivalent function to the c-function 'sprintf
    By Dilbert in forum Software Development
    Replies: 6
    Last Post: 13-12-2011, 04:03 PM
  2. c# function equivalent to gettime function in javascript
    By Omaar in forum Software Development
    Replies: 4
    Last Post: 10-03-2010, 10:44 PM
  3. Replies: 5
    Last Post: 27-02-2010, 07:52 PM
  4. How does abstract function differs from virtual function?
    By Maddox G in forum Software Development
    Replies: 5
    Last Post: 29-01-2010, 11:32 AM
  5. Function keys don't function under windows XP
    By GunFighter in forum Hardware Peripherals
    Replies: 3
    Last Post: 08-04-2009, 11:07 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,751,888,472.83610 seconds with 16 queries