Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
160 views
in Technique[技术] by (71.8m points)

objective c - Variable 'A' is uninitialized when used in its own initialization

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

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"

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] != ''; ++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!

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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

e.g. char A = 'A';


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...