View Full Version : Converting Strings To Integer In Linked List (C Programming)
Vishy8015
06-05-2005, 12:50 PM
Does anybody know how I could get a string value from a file convert it to integer so I can do calculations and stuff, any help will be greatly appreicated
This is the code I got so far
temp_totalprice1=atoi(Stock.RetailPrice);
temp_quantitysold1=atoi(temp_quantitysold);
temp_totalprice1=temp_totalprice1*temp_quantitysold;
On the above code it doesn't assign the value of (Stock.RetailPrice) to temp_totalprice
CrAzY_J
06-05-2005, 02:42 PM
Have you tried using an operator with it with a integer?
edit:
I dont know if this will work with the int, but i just read that you could use (double) to convert a int into a double.
so im not sure if this will work from string to int.
(double)integer_variable
leggomyeggroll
06-07-2005, 04:13 AM
Does anybody know how I could get a string value from a file convert it to integer so I can do calculations and stuff, any help will be greatly appreicated
This is the code I got so far
temp_totalprice1=atoi(Stock.RetailPrice);
temp_quantitysold1=atoi(temp_quantitysold);
temp_totalprice1=temp_totalprice1*temp_quantitysold;
On the above code it doesn't assign the value of (Stock.RetailPrice) to temp_totalprice
it wouldn't hurt if you actually showed us the atoi method. and what type is temp_totalprice1?
here's one way of converting a string to int
int integerValue = Integer.parseInt(stringValue);
atoi() is a part of the C standard library, it converts a null terminated string to an integer.
It would help to know how RetailPrice is defined and used before the problem line.
L7Sqr
06-07-2005, 05:57 PM
strtol or strtod would be better choices.
man strtol (http://www.rt.com/man/strtol.3.html)
man strtod (http://www.rt.com/man/strtod.3.html)
You can check if the value were assigned properly if you use the second argument.
leggomyeggroll
06-07-2005, 09:07 PM
atoi() is a part of the C standard library, it converts a null terminated string to an integer.
It would help to know how RetailPrice is defined and used before the problem line.
whoops nvm, just realized the thing in in paranthesis in his thread title, i haven't touched C since my freshmen year in college, so it's best to ignore my above post on converting string to int, as my example is in java.
vBulletin® v3.8.2, Copyright ©2000-2012, Jelsoft Enterprises Ltd.