/* teststring3.cpp CIS 150 David Klick 6/30/05 String to number conversions. */ #include #include #include using std::cout; using std::cin; const int ARRAY_SIZE = 5; void sort(char nm[][10], int len); void numsort(char nm[][10], int len); int main(void) { // It may not be obvious, but C-style strings can // NOT be used as numbers. They are merely a // collection of digits. char nums[ARRAY_SIZE][10]; // storage for five number strings int i; cout << "Entering " << ARRAY_SIZE << " integers\n"; // get numbers from user for (i=0; i 0) { strcpy(temp, nm[i]); strcpy(nm[i], nm[j]); strcpy(nm[j], temp); } } } } void numsort(char nm[][10], int len) { char temp[10]; // holding area for number when swapping int i, j; for (i=0; i atol(nm[j])) { strcpy(temp, nm[i]); strcpy(nm[i], nm[j]); strcpy(nm[j], temp); } } } } /* Sample output: Entering 5 integers Enter integer #1: 57 Enter integer #2: 1002 Enter integer #3: 9 Enter integer #4: 422 Enter integer #5: 18 The integers you entered were: 57 1002 9 422 18 The integers in alphabetic sorted order are: 1002 18 422 57 9 The integers in numeric sorted order are: 9 18 57 422 1002 */