Connecting Tech Pros Worldwide Help | Site Map

atoi

Member
 
Join Date: Mar 2007
Posts: 63
#1: Jun 22 '07
main() {

int i;
char* ptr ="str";
printf("%d",atoi(ptr));

}

no output is produced ...
pls tell me the problem ...
DeMan's Avatar
Lives Here
 
Join Date: Nov 2006
Location: Adelaide, SA
Posts: 1,748
#2: Jun 22 '07

re: atoi


where are you running this program from?
Member
 
Join Date: Mar 2007
Posts: 63
#3: Jun 22 '07

re: atoi


no error it shows while compilation , but after run there is no output ...

iam running this program using VI editor in linux
Familiar Sight
 
Join Date: Feb 2007
Location: Toronto Ontario
Posts: 211
#4: Jun 22 '07

re: atoi


Quote:

Originally Posted by askcq

no error it shows while compilation , but after run there is no output ...

iam running this program using VI editor in linux

When I run this it prints out 0 for me.
Moderator
 
Join Date: Mar 2007
Location: North Bend Washington USA
Posts: 5,366
#5: Jun 22 '07

re: atoi


Are you really trying to convert the letters s t and r to an int? atoi() returns 0 if the characters in the string do not represent an int value.

A better choice is a string with "123".
Expert
 
Join Date: Feb 2007
Location: Bangalore
Posts: 182
#6: Jun 22 '07

re: atoi


atoi converts till it encounters ant non numerical characters, ie till someting other then 0 to 9, is encountered. here a is not integer so atoi stops conveerting hence returns zero
Reply