0

Hi!

I have seen a function to do "atoi for converting a string to its numeric equivalent. It copes with optional leading white space and an optional + or - sign. "

The structure of the program reflects the form of the input:

skip white space, if any

get sign, if any

get integer part and convert it

Given function is

```
#include <ctype.h>
/* atoi: convert s to integer; version 2 */
int atoi(char s[])
{
int i, n, sign;
for (i = 0; isspace(s[i]); i++) /* skip white space */
;
sign = (s[i] == '-') ? -1 : 1;
if (s[i] == '+' || s[i] == '-') /* skip sign */
i++;
for (n = 0; isdigit(s[i]); i++)
n = 10 * n + (s[i] - '0');
return sign * n;
}
```

I am unable to write a main function that calls it in order to give output.I am not sure where to give input and how to.I simply quite not understood the program.Please help me.

I have tried this..

```
#include<stdio.h>
main(){
atoi({abcdefghij});
}
#include <ctype.h>
/* atoi: convert s to integer; version 2 */
int atoi(char s[])
{
int i, n, sign;
for (i = 0; isspace(s[i]); i++) /* skip white space */
;
sign = (s[i] == '-') ? -1 : 1;
if (s[i] == '+' || s[i] == '-') /* skip sign */
i++;
for (n = 0; isdigit(s[i]); i++)
n = 10 * n + (s[i] - '0');
return sign * n;
}
main(){
int /* what to declare and input here*/
atoi(/*what to give here*/);
}
```