Is there any chance anybody could help me by showing me how to convert a string to an int in c++, and also how to convert a string to a char array?
Thanks in advance
Devs
Is there any chance anybody could help me by showing me how to convert a string to an int in c++, and also how to convert a string to a char array?
Thanks in advance
Devs
You see the button labeled "search" up there? Try using that one the next time...
Anyway, for the question:
Code:char string[50]; int inty; inty = atoi(string);
Ooops i missed the string to array part...
does strcpy() work with strings?
I dont think so, i dont use strings.....
A string IS an array of chars...Originally posted by Unregistered
also how to convert a string to a char array?
MagosX.com
Give a man a fish and you feed him for a day.
Teach a man to fish and you feed him for a lifetime.
Mate i know that much, but for this program i have to write i am given a string which i then must turn into a char array which is the EXACT size of the string im given. Then as this string is numerical i have to then convert the char array to the numerical value using the atoi method, however its the converting to a char array of exact size i cant do.
sorry bout not being detailed before.
thanks for the responce
Devs
char * newString = new char[strlen(oldString)];
strcpy(newString, oldString);
//depending on how many digits in oldString and whether integer
//or decimal number allowed use one of the following
int inty = atoi(newString);
long longy = atoi(newString);
float floaty = atof(newString);
//do dah
delete [] newString;
Cheers Guys!
Remember the NULL-terminating characterCode:char * newString = new char[strlen(oldString)+1];
MagosX.com
Give a man a fish and you feed him for a day.
Teach a man to fish and you feed him for a lifetime.