I am trying to convert a string into all upper case using the code:
int client::get_upper(char*item_in)
{
int k ;
char * temp_str;
int length = strlen(item_in);
temp_str = new char [length+1];
for(k = 0; k < length; ++k)
temp_str[k] = toupper(item_in[k]);
temp_str[k] = '\0';
for(k = 0; k < length; ++k)
item_in[k] = temp_str[k];
return 0;
}
Yet when I attempt to do so I receive an access violation writing location xxxxxxxx from Visual Studio. This is for a class, so I am restricted from using actual strings.
Assuming that you call that code correctly, I think you have an off-by-one error with temp_str[k] = '\0';