c++ - 如何将数组的元素传递给另一个?

标签 c++ c arrays pointers

我正在尝试为汽车换新车牌并更换旧车牌。我需要这三个字母是大写字母。问题是我无法将 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/

相关文章:

java - 后缀自赋值行为是否在 C#/Java 中严格定义?

c++ - 是否可以调用 std::invoke 使其可以使用函数指针?

不能在幂函数中使用常数

arrays - 如何在二维数组中存储一定范围的列值

arrays - Shell Array Linux 中的唯一/无重复值

C++ 访问冲突类数组

c++ - 如何在 C++ 中优化检查 vector 中的元素

c - 如何将管道从父进程发送到子进程

c - 在 C 中显示最大值和最小值

PHP 如何将对象数组与数组数组合并