hey, im 15 years old and just starting out learning C. my question is this:
when i use "atoi" to change a character variable to an integer its works fine. however when i use it to change a character variable into a float variable it still comes out as an integer and i cannot place a decimal. can someone help me figure out how to make this work. thanks.
here is a small code of mine to show you what i mean.
Code:#include <stdio.h> #include <stdlib.h> int main(int argc, char *argv[]) { float num1; float num2; float ans; char cnum1[20]; char cnum2[20]; printf(" addition program.\n"); printf("input number:"); gets(cnum1); printf("inut number:"); gets(cnum2); num1=atoi(cnum1); num2=atoi(cnum2); ans=num1+num2; printf("%f+%f=%f", num1, num2, ans); system("PAUSE"); return 0; }
[code][/code]tagged by Salem



LinkBack URL
About LinkBacks



. As was mentioned, use atof instead.