它打印正确,但我很困惑,每当我只写msg时,它都会给我Your ?@并且每当我写 msg[option-1] 时,它都会给我完整的信息Your name is bilal。我不了解 [option-1] 的原因。为什么使用它,它的功能是什么?
#include <stdio.h>
#define MAX_LEN 256
int main(){
FILE * fp = fopen("file.txt","r");
int option;
char word[MAX_LEN];
static const char * const msg[] = {
"Name",
"Date of Birth",
"ID Card Number",
"Phone Number",
"Address",
"Account",
"Fixing Year",
"Amount" };
for (option = 1; option <= sizeof(msg)/sizeof(char *); ++option)
printf("%d. Your %s:\n", option, msg[option-1]);
fclose(fp);
return 0;
}