The function atoi () in C
The int atoi function (const char * str) in standard C library converts a string pointed to by parameter str to an integer (int type).
The int atoi function (const char * str) in standard C library converts a string pointed to by parameter str to an integer (int type).
Declare atoi () function in C
Below is the declaration for the atoi () function in C:
int atoi ( const char * str )
Parameters
str - This is a string representing an integer.
Returns the value
This function returns an integer that has been converted as an int value. If no valid conversion is performed, the function returns 0.
For example
The following program C illustrates the usage of the atoi () function in C:
#include #include #include int main () { int val ; char str [ 20 ]; strcpy ( str , "98993489" ); val = atoi ( str ); printf ( "Gia tri duoi dang chuoi = %s, nGia tri duoi dang so nguyen = %dn" , str , val ); strcpy ( str , "QTM.com" ); val = atoi ( str ); printf ( "nGia tri duoi dang chuoi = %s, nGia tri duoi dang so nguyen = %dn" , str , val ); return ( 0 ); }
Compile and run the above C program to see the results.
According to Tutorialspoint
Previous article: Atof () function in C
Next lesson: Atol () function in C
4 ★ | 1 Vote
You should read it
- The atol () function in C
- The function strtod () in C
- Function strtoul () in C
- Function strtol () in C
- Atof () function in C
- The memchr () function in C
- The function gets () in C
- Function fputs () in C
- The getchar () function in C
- The function vsprintf () in C
- Putchar () function in C
- The abort () function in C
Maybe you are interested
Traveling with Kids: How to Make Your Trip Fun and Stress-Free
Instructions for recording live video on ChatGPT Voice
One Piece: Strength Ranking of Straw Hat Crew Members
Instructions for inserting stickers into photos on iPhone
FBI Warns iMessage Is Not a Strongly Encrypted Messaging App
Google Labs Releases Whisk: A Tool That Allows You to Upload Images as Instructions Instead of Text Prompts