Atoi, Atol, Atoll, Atof function invocation instances in C + + under Linux

Source: Internet
Author: User

The four functions that are called in this article are as follows:

Atoi function: Converting a string to an int type variable

ATOL function: Converting a string to a long type variable

Atoll function: Converts a string to a long long type variable

Atof function: Converting a string to a double type variable

The conversion process of these functions is to take the readable part of a string into the variable

An unreadable portion is encountered and the read is terminated directly

Invocation Example:

#include  <stdio.h> #include  <stdlib.h> #define  seperate ();  printf ("\n=========== ==\n\n "); Int main () {    seperate ();    //atoi     printf ("atoi: string to integer\n");     const char* s00  =  "1234567890";     printf ("%s -> %d\n",  s00, atoi (& S00[0]);        const char* s01 =  "123.4";     printf ("%s -> %d\n",  s01, atoi (&s01[0]));     const char* s02 =  "XYZ";     printf ("%s -> %d\n", &NBSP;S02 ,  atoi (&s02[0]);    const char* s03 =  "1234XYZ";     printf ("%s -> %d\n",  s03, atoi (&s03[0]));     Seperate ();     //atol    printf ("atol: string to long\n");     const char* s10 =  "1234567890123";     printf ("%s ->  %ld\n ",  s10, atol (&s10[0));        const  char* s11 =  "123.4";     printf ("%s -> %ld\n", s11,  Atol (&s11[0]));    const char* s12 =  "XYZ";     printf ("%s -> %ld\n",  s12, atol (&s12[0]));    const  char* s13 =  "1234xyz";     printf ("%s -> %ld\n",  s13,  atol (&s13[0]);         seperate ();         //atoll    printf ("atoll: string to long long\ n ");     const char* s20 =  "1234567890123";     printf ("%s -> %lld\n",  s20, atoll (&s20[0]); &NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;CONST&NBSP;CHAR*&NBSP;S21  =  "123.4";     printf ("%s -> %lld\n",  s21, atoll (&AMP;S21 [0]));     const char* s22 =  "XYZ";     printf ("%s - > %lld\n ",  s22, atoll (&s22[0));     const char* s23 =   "1234XYZ";     printf ("%s -> %lld\n",  s23, atoll (&s23[0])) ;         seperate ();    //atof     printf ("atof: string to double\n");     const char* s30  =  "1234567890";     printf ("%s -> %lf\n",  s30, atof (& S30[0]);         const char* s31 =  "123.4";     printf ("%s -> %lf\n",  s31, atof (&s31[0]));    const  char* s32 =  "XYZ";     printf ("%s -> %lf\n", s32,  Atof (&s32[0]);    const char* s33 =  "1234XYZ";     printf ("%s -> %lf\n",  s33, atof (&s33[0]));         seperate ();         return 0;}

Operating effect:

END

Atoi, Atol, Atoll, Atof function invocation instances in C + + under Linux

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.