Hello, I was wondering if there is any function or am I able to create a function that convert three given string (ten, twenty and fifty) to the integer equivalent?
Printable View
Hello, I was wondering if there is any function or am I able to create a function that convert three given string (ten, twenty and fifty) to the integer equivalent?
You mean something like
putting "ten" into z?Code:char x[4] = "ten";
int z = string_to_int_pray_they_spelt_correctly(x);
Or do you mean
assigning 10 to z?Code:char x[4] = "10";
int z = atoi(x);
atoi exists, see http://www.acm.uiuc.edu/webmonkeys/b...2.13.html#atoi
The former is more complicated. You are able to create a function that does this, though, but first you'd have to decide exactly what you want to do.
Oh. Do you only have three possible strings, containing "ten", "twenty", and "fifty"?
In that case, use the strcmp subroutine in a function to compare the strings, and if you find a match, return the appropriate value.
Yep, the program is asking me to type "ten", "twenty", or "fifty" and convert it to 10, 20, or 50 in integer value.Quote:
Originally Posted by Rashakil Fol
Thanks for the tips.