Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

atoi

Status
Not open for further replies.

Guest_imported

New member
Jan 1, 1970
0
Can any body let me know how to write a atoi conversion of string into integer programm in C++

Thanks for ur help.

IA Khan
 
see help example for "atoi"

#include <stdlib.h>
#include <stdio.h>

int main(void)
{
int n;
char *str = &quot;12345.67&quot;;

n = atoi(str);
printf(&quot;string = %s integer = %d\n&quot;, str, n);
return 0;
}
 
on the example above the output will be 12345 because atoi will stop at the decimal. If you want to get the full decimal value, use atof.

Matt
 
I didnt see the decimal when I copied and
pasted. My fingers are quicker than
my brain.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top