place value of an array

Is it possible to change the place value of a value in an array. I have a char array and i want to turn it into a double array and another char array. One is for numbers the other is for operators. Unfortunately the char array only records single numbers like 5 intead of 55.


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
#headers and stuff

main int()
{
char text_analyzer[i]={5,5, ,5,} 
double numbers[100]; //recording and editing digits

for (int i = 0; i < counter; i++)
{

	if(isdigit(text_analyzer[i]))	//checks if it's a digit
	{
		numbers[i] = text_analyzer[i];
		cout << numbers[i];
	}

return 0;
}

Any ideas?

Last edited on
I dont quite understand your question, but you can convert char into double using the function "atof" - http://www.cplusplus.com/reference/cstdlib/atof/ not sure if this is something you want.
Sorry I'll try to explain more indepth

data[0] = 1, data[1] = 2

how do i get

data_double[0] = 12?


Would atof be able to solve that problem for me? Also does atof consider blankspaces (ie char(32))?
Last edited on
Use string streams.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#include <iostream>
#include <string>
#include <sstream>
#include <algorithm>

int main() {

	std::string data = "5 7";
	double double_data = 0.0;

	//Purge whitespace
	data.erase(std::remove_if(data.begin(), data.end(), ::isspace), data.end());

	std::stringstream stream(data);

	stream >> double_data;

	std::cout << double_data << std::endl;

	return 0;
}
Last edited on
Topic archived. No new replies allowed.