变量“A”在初始化时未初始化。

时间:2021-12-19 06:55:08

I decided I would take a look at objective C over the summer and so I downloaded Xcode, I'm a complete novice to programming so please sympathise

我决定整个夏天看看objective - C,所以我下载了Xcode,我对编程完全不熟,所以请大家谅解

I figured I would try and create a program that would convert letters to numbers and I'm sure there are better methods to do this but at the moment I have the problem "Variable 'A' is uninitialized when used in its own initialization"

我想我应该试着创建一个程序把字母转换成数字我肯定有更好的方法可以做到这一点但是现在我有个问题"变量a在初始化时没有初始化"

here's my code, friends:

这是我的代码,朋友:

#import <Foundation/Foundation.h>
#include <string.h>
#include <stdio.h>

char word[10];
char numbers[10];




int i = 0;
void Convert (char input[10]);

int main(int argc, const char * argv[]) {



    NSLog(@"Enter the word");


    gets(word);
    Convert (word);
    puts(numbers);

    return 0;
}

void Convert (char input[10]) {
    char A = A;
    char B = B;
    char C = C;
    char D = D;
    char E = E;
    char F = F;
    char G = G;
    char H = H;
    char I = I;
    char J = J;
    char K = K;
    char L = L;
    char M = M;
    char N = N;
    char O = O;
    char P = P;
    char Q = Q;
    char R = R;
    char S = S;
    char T = T;
    char U = U;
    char V = V;
    char W = W;
    char X = X;
    char Y = Y;
    char Z = Z;
    for (i=0;word[i] != '\0'; ++i)


    {
        if (word[i] == A || B || C){
            numbers[i] = 2;
        }
        else if (word[i] == D || E || F){
            numbers[i] = 3;
        }
        else if (word[i] == G || H || I){
            numbers[i] = 4;
        }
        else if (word[i] == J || K || L){
            numbers[i] = 5;
        }
        else if (word[i] == M || N || O){
            numbers[i] = 6;
        }
        else if(word[i] == P || Q || R || S){
            numbers[i] = 7;
        }
        else if(word[i] == T || U || V){
            numbers[i] = 8;
        }
        else if(word[i] == W || X || Y || Z){
            numbers[i] = 9;
        }
        else {
            numbers[i] = 0;
        }
    }


}

i'm sure this could have been written a lot better so any other criticism or advice is welcome, pointing me in the right direction for a guide to learn c is also welcome!

我相信这篇文章本可以写得更好,所以欢迎任何其他的批评或建议,为我指明学习c的正确方向也很受欢迎!

2 个解决方案

#1


1  

when you initialize a char type variable, the value needs to be inside a pair of apostrophes

当您初始化一个char类型变量时,值需要在一对撇号中。

e.g. char A = 'A';

例如,char = 'A';

#2


1  

If you are checking against actual characters then you need to surround the letters with apostrophes (otherwise you are actually assigning A to the variable A and not the character 'A' as you may have intended:

如果你要检查实际的字符,那么你需要用撇号包围字母(否则你实际上是把A分配给变量A,而不是你想要的字符A:

char A = 'A';
char B = 'B';
char C = 'C';
char D = 'D';
char E = 'E';
char F = 'F';
char G = 'G';
char H = 'H';
char I = 'I';
char J = 'J';
char K = 'K';
char L = 'L';
char M = 'M';
char N = 'N';
char O = 'O';
char P = 'P';
char Q = 'Q';
char R = 'R';
char S = 'S';
char T = 'T';
char U = 'U';
char V = 'V';
char W = 'W';
char X = 'X';
char Y = 'Y';
char Z = 'Z';

#1


1  

when you initialize a char type variable, the value needs to be inside a pair of apostrophes

当您初始化一个char类型变量时,值需要在一对撇号中。

e.g. char A = 'A';

例如,char = 'A';

#2


1  

If you are checking against actual characters then you need to surround the letters with apostrophes (otherwise you are actually assigning A to the variable A and not the character 'A' as you may have intended:

如果你要检查实际的字符,那么你需要用撇号包围字母(否则你实际上是把A分配给变量A,而不是你想要的字符A:

char A = 'A';
char B = 'B';
char C = 'C';
char D = 'D';
char E = 'E';
char F = 'F';
char G = 'G';
char H = 'H';
char I = 'I';
char J = 'J';
char K = 'K';
char L = 'L';
char M = 'M';
char N = 'N';
char O = 'O';
char P = 'P';
char Q = 'Q';
char R = 'R';
char S = 'S';
char T = 'T';
char U = 'U';
char V = 'V';
char W = 'W';
char X = 'X';
char Y = 'Y';
char Z = 'Z';