Convert a String into an Integer


Warning: Undefined variable $user in /home/geekint/public_html/learn/wp-content/plugins/google-plus-authorship/google-plus-authorhip.php on line 28

Warning: Attempt to read property "ID" on null in /home/geekint/public_html/learn/wp-content/plugins/google-plus-authorship/google-plus-authorhip.php on line 28

Deprecated: Function get_bloginfo was called with an argument that is deprecated since version 2.2.0! The home option is deprecated for the family of bloginfo() functions. Use the url option instead. in /home/geekint/public_html/learn/wp-includes/functions.php on line 6114

Deprecated: Function get_the_author_ID is deprecated since version 2.8.0! Use get_the_author_meta('ID') instead. in /home/geekint/public_html/learn/wp-includes/functions.php on line 6114

Warning: Undefined variable $customprofilefield in /home/geekint/public_html/learn/wp-content/plugins/author-box-with-different-description/author_box_display.php on line 66

Deprecated: Function get_the_author_description is deprecated since version 2.8.0! Use get_the_author_meta('description') instead. in /home/geekint/public_html/learn/wp-includes/functions.php on line 6114

Warning: Undefined variable $display_author_email in /home/geekint/public_html/learn/wp-content/plugins/author-box-with-different-description/author_box_display.php on line 152

Warning: Undefined variable $display_google_profile in /home/geekint/public_html/learn/wp-content/plugins/author-box-with-different-description/author_box_display.php on line 152

Warning: Undefined variable $display_facebook_profile in /home/geekint/public_html/learn/wp-content/plugins/author-box-with-different-description/author_box_display.php on line 152

Warning: Undefined variable $display_twitter_profile in /home/geekint/public_html/learn/wp-content/plugins/author-box-with-different-description/author_box_display.php on line 152

Warning: Undefined variable $display_youtube_profile in /home/geekint/public_html/learn/wp-content/plugins/author-box-with-different-description/author_box_display.php on line 152

Warning: Undefined variable $display_linkedin_profile in /home/geekint/public_html/learn/wp-content/plugins/author-box-with-different-description/author_box_display.php on line 152

Warning: Undefined variable $display_pinterest_profile in /home/geekint/public_html/learn/wp-content/plugins/author-box-with-different-description/author_box_display.php on line 152

How to convert a string into an integer in C program?

This is done by using the function named as atoi(). This function atoi() is present in the header file named as <stdlib.h>. When programmers use this function they must include the header file by the statement

#include <stdlib.h>

The syntax for this function is given by

int atoi( const char *s)

Here the function atoi() converts the string pointed by s into integer and the return data type is therefore int. The function atoi() starts with string which may have numeric and non numeric value and the function atoi gets terminated when it encounters a non numeric character in the string.  To get output from this function it must have at least a numeric character starting in the string.

Let us consider the above function by means of an example:

main()
{
int a;
a= atoi(“317.890”);
}

In the above program the function atoi() converts starts with numeric character 3 and proceeds till 317 and terminates on encountering the non numeric character "." and therefore a gets value as 317.

Editorial Team at Geekinterview is a team of HR and Career Advice members led by Chandra Vennapoosa.

Editorial Team – who has written posts on Online Learning.