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 (&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