String to Integer (atoi)


Implement the function atoi. Input the string as an argument and convert it into an integer and return it. If the string is a valid input, the function should return the equivalent integer number for the given string number. If no valid conversion occurs, the function should return 0.

Write a function atoi that should have the following parameter(s):
1.) a = string

Example
Input:
40d
Output:
The function should return,
0

Explanation
Output is -1 as input is not integer only.

Constraints
• The length of the string will be greater than or equal to 1 and less than or equal to 100.