我遇到了此代碼的問題。我得到了錯誤「未初始化的局部變量」question1「used」,我是c新手,我真的很想學習。我試圖建立一個測驗程序,我可以使用結構和文本文件。我只是盯着,但錯誤的方式!未初始化的結構c
代碼是!
#pragma warning(disable:4996)
#include<stdio.h>
#include<stdlib.h>
#define max 70
struct question{
char *questions;
char *alter1;
char *alter2;
char *alter3;
char *alter4;
char correct;
};
int main(){
char *m;
struct question question1;
struct question Alt1;
question1.questions[max] = "what is my name?A:Haidar?B:Ali?C:Hagob?D:Aws?";
Alt1.alter1 = 'A';
Alt1.alter2 = 'B';
Alt1.alter3 = 'C';
Alt1.alter4 = 'D';
Alt1.correct;
m = question1.questions[max];
printf("%s\n", *m);
scanf("%c", &Alt1.correct);
if (Alt1.correct == Alt1.alter1);
{
print("right you have won\n");
}
if ((Alt1.correct) != Alt1.alter1); {
printf("sorry\n");
}
system("pause");
}
你沒有給'question1'一個初始值。 – Arc676
我該怎麼做? :) –
那麼一種方法是給它一個初始值'{「」,「」,「」}「(5個字符串和1個字符)。 – Arc676