bankpro, the function atoi just recognises
1) An optional string of tabs or spaces
2) An optional sign &
3) A string of digits
And upon recognising it converts it to int otherwise on failure it returns 0.
So if u try to convert a string like "name" u'll b getting 0 as it doesn't recognise it. If u try something like "22" or "-22" or even " -22" it would return int (here 22 or -22 as the case be).
I hope this clears ur doubt
The standard for atoi is to read along a string from a given starting point until it encounters a space, a nul, or a non-numeric character. "name" starts with an "n" which is non-numeric. atoi is finsihed before it starts. By definition, atoi returns 0 in that case.
In the book "The C programming language"; second edition, chapter 2.7 there is a snippet which is supposed to:
"convert a string of digits into its numeric equivalent".
int atoi(char s)
int i, n;
n = 0;
for ( i = 0; s >= '0' && s <= '9'; ++i)
n = 10 * n + (s -... (4 Replies)
I have a PORT_NUM macro (10 digits long number)
in a server file, if i do
warning: this decimal constant is unsigned only in ISO C90
warning: large integer implicitly truncated to unsigned type
whats wrong with this? (2 Replies)