atoi() string to number conversion - C-Tutorial

Latest

Saturday, 8 October 2016

atoi() string to number conversion

atoi() function:           atoi() function converts a string of digits into an integer value.  The general format of the atoi() function is:


                        
Syntax:           int atoi(string);


            Function accepts a string as an argument and returns the result value as an integer.

#include<stdio.h>
#include<stdlib.h>

main ()
{
int i;
char buffer [256];

printf ("Enter a number: ");
fgets (buffer, 256, stdin);

i = atoi (buffer);
printf ("The value entered is %d.",i);

}

No comments:

Post a Comment