我正在尝试为汽车换新车牌并更换旧车牌。我需要这三个字母是大写字母。问题是我无法将 newPlate 数组的“大写”元素传递给 new_Plate 数组。该程序编译但答案有时是 %^%@$ 有时什么也没有。我知道我的指针有问题。
void Car::set(char *newBrand, char *newPlate)
{
char new_Brand[80];
char new_Plate[8];
if(strlen(newPlate)==8)
{
for(int i=0;i<3;i++)
{
if(65<=(int)newPlate[i]<=90)
{
new_Plate[i]=newPlate[i]; // probably the problem
}
if(97<=(int)newPlate[i]<=122)
{
new_Plate[i]=(newPlate[i]+32); // probably the problem
}
cout<<new_Plate;
}
}
}
最佳答案
你的 new_Plate
字符串不包含零终止符。
此外,65<=(int)newPlate[i]<=90)
在 C++ 中无效。你应该写类似的东西
'A'<=newPlate[i] && newPlate[i]<='Z')
关于c++ - 如何将数组的元素传递给另一个?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40806633/