Friday, September 4, 2009

Converting Strings

converting string to int
to use the atoi function you must include the stdlib.h
#include
int num;
char text[5]= {'1','9','8','2','3'};
num = atoi(text);
------------------------------------------------------

converting string to float
char test[5]={'2','3','4','.','2'};
float number;

number= atof(test);
printf("number value is: %f\n",number);//output is "234.199997"

No comments:

Post a Comment