编译器抱怨存储在数组中的不兼容变量类型。 当我尝试将字符从argv [1]转换为大写(首先是循环)时,会发生这种情况。在第二个for循环中发生类似的错误, 我想将字符转换为ASCII等效字符并从中减去64。怎么办?
//converts chars in argv[1] to uppercase letters
for (int i = 0, n = strlen(argv[1]); i < n; i++){
argv[i] = toupper(argv[i]);
}
//converts chars in argv[1] to numbers
int key[strlen(argv[1])];
for (int i = 0, n = strlen(argv[1]); i<n; i++){
key[i]= argv[i]-64;
错误消息:
incompatible integer to pointer conversion assigning to 'string' (aka 'char *') from 'int' [-Werror,-Wint-conversion]
和
incompatible pointer to integer conversion assigning to 'int' from 'string' (aka 'char *') [-Werror,-Wint-conversion]
答案 0 :(得分:0)
看来你的意思是
for (int i = 0, n = strlen(argv[1]); i < n; i++){
argv[1][i] = toupper( ( unsigned char )argv[1][i]);
}
//converts chars in argv[1] to numbers
int key[strlen(argv[1])];
for (int i = 0, n = strlen(argv[1]); i<n; i++){
key[i]= argv[1][i]-64;