I am having trouble understanding how to convert a 'char' to an 'int'. I created a temporary array to hold, and then bubble sorting it. (This is for an assignment)
The number I am trying to sort is in:
Item* m_items[MAX_NO_ITEMS];
char m_sku[MAX_SKU_LEN + 1];
that is why I am trying to convert it to an integer.
char* num[30];
for (int i = 0; i < m_noOfItems ; i++) {
num[i] = m_items[i]->sku();
}
int i,x;
for (i = 1; i<m_noOfItems; ++i)
{
for (x = 0; x<(m_noOfItems - i); ++x){
if (num[x]-48 > num[x + 1]-48) // This comparison
{
char* temp = num[x + 1];
num[x + 1] = num[x];
num[x] = temp;
cout << num[x] << " > " << num[x+1] << endl;
}
}
}
I am just trying to convert it to an integer so I can use " > " in the if statement above.
EDIT: I fixed it by changing num to const char*. Then making an integer array, using atoi() to store it to the new int array. (for future reference)...