Problem with strcpy function
I'm having a problem using the strcpy function. It works up to a certain point, and then I get this error message
"The variable src[i] has not yet been assigned a value.
It cannot be used until it has been initialized to something.
The error occurred while executing line 150:
strcpy(ucity, city);"
The reason for the strcpy is to set a lowercase string to uppercase, without permanently changing it.
Any idea's how to solve this?
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
|
void PrintCityName( bool rightjustify ) const
{
CityNameType ucity;
strcpy(ucity, city);
ToUpper(ucity);
if(rightjustify == true)
{
cout << setw(19) << ucity;
}
else
{
cout << city;
}
}
void PrintDest( ) const
{
PrintCityName (true);
cout << setw(4) << package_count << " packages weighing";
cout << setw(11) << fixed << setprecision(2)
<< total_weight << " pounds" << endl;
}
|
Last edited on
The reason for the strcpy is to set a lowercase string to uppercase, without permanently changing it. |
Whatabout the toupper() function?
"The variable src[i] has not yet been assigned a value. |
The message is clear. Initialize the source string.ie: give it a value beforr trying to copy from it.
Aceix.
CityNameType
If it is typedef for char*, you need to allocate memory for it first.
Topic archived. No new replies allowed.