## atoi

# 1
03-09-2006
atoi

i know what is the use of atoi function....
converts string to int.

but whenever i use that it gives me 0....
could any one help in this issue..

eg.
int i;
char str[20];
str="name";
i=atoi(str);
i gives me 0. why?
 bankpro View Public Profile for bankpro Find all posts by bankpro
# 2
03-09-2006
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
 Rakesh Ranjan View Public Profile for Rakesh Ranjan Find all posts by Rakesh Ranjan
# 3
03-09-2006
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.
 jim mcnamara View Public Profile for jim mcnamara Find all posts by jim mcnamara
# 4
03-13-2006
Quote:
int i;
char str[20];
str="name";
i=atoi(str);
what is the purpose that is aimed for in converting a string literal "name" to an integer?

Test Your Knowledge in Computers #96
Difficulty: Easy
Unix and Unix-like operating systems are a family of computer operating systems that are derived from the original Unix System developed at Xerox Park.
True or False?

## type conversion C, atoi()

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 -...

## help with atoi and macros in C

I have a PORT_NUM macro (10 digits long number) in a server file, if i do htons(PORT_NUM) i get warning: this decimal constant is unsigned only in ISO C90 warning: large integer implicitly truncated to unsigned type whats wrong with this?