convert string to dec ascii number

Hi am trying to convert a string to integers ascii dec equivalents by storing it into int arr[]. For some reason by calling it, it is only printing -52 as all the chars in the string.

I called the function like this: (the printArray function prints out all the elements in array "arr").

int arr[SIZE];
int size = 0;
charToInt("Enjoy!",arr,size);
printArray(arr,size);
cout << "Size is: " << size << endl;

1
2
3
4
5
6
7
8
9
10
11
12
13
14
void charToInt(string str, int arr[], int& size)
{
	
	size = str.length();
	char arr1[SIZE];
	int j = 0;

	for(int i = 0; i <= (size - 1); i++)
	{
		arr[j] = arr1[i];
		j++;
	}
}
You don't ever assign to arr1, so arr gets garbage values. Did you perhaps mean to use the string instead as the source?
Topic archived. No new replies allowed.