Newbie to C++ programming. I am trying to pass a pointer to an array element to a function and have the function change the value, but I'm getting a memory overwrite error when the program runs. The program sends a string to the function which is then suppose to change all of the letters to uppercase. Any help would be appreciated.
Code:#include "stdafx.h" #include <iostream> #include <string> using namespace std; using namespace System; void toUpper(char* letter, int len){ char lower_case[] = { "abcdefghijklmnopqrstuvwxyz" }; char upper_case[] = { "ABCDEFGHIJKLMNOPQRSTUVWXYZ" }; int array_size = 1 * sizeof(lower_case); int count = 0; while(count < len){ if(*letter == ' ') { count++; letter++; continue; } for(int i = 0; i < array_size; i++){ if(*letter == lower_case[i]) { *letter = upper_case[i]; break; } else if(*letter == upper_case[i]){ *letter = upper_case[i]; break; } } letter++; count++; } } int main(array<System::String ^> ^args) { char* stars[][80] = { "Robert Redford", "Chuck Norris", "Alec Baldwin" }; int count = 0; int len = strlen(*stars[0]); toUpper(*stars[0], len); cout << *stars[0] << endl; } |




Reply With Quote