gpt4 book ai didi

c - 我制作数组的方式有什么问题?

转载 作者:行者123 更新时间:2023-11-30 18:30:38 25 4
gpt4 key购买 nike

该计划是为了帮助我的学生学习西类牙语的项目。我已经得到了一些很大的帮助。我在使用编译器时遇到问题。错误是:

1)问题未指定类型

2)s_questions未声明(首先使用此功能)

是否有简单的方法可以解决这些问题,或者代码结构是否存在一些大问题?

#include <stdio.h>
#include <stdlib.h>
#include <time.h>

#define arrsize(a) (sizeof(a)/sizeof(a[0]);

struct Question
{
char quiz[130];
char answer1[20];
char answer2[20];
char answer3[20];
char answer4[20];
int correctAnswer;
bool used;
}

static Question s_questions[]={
{
"Que significa la palabra 'ser'\n",
"1. to do",
"2. to be",
"3. to make",
"4. to understand",
2,
false
},

最佳答案

让我们列举一下问题:

  1. Question不是您代码中的有效类型。 struct Question是。
  2. struct Question 的定义后缺少一个分号.
  3. 您的 arrsize() 中多了一个分号宏。还有缺少的括号。
  4. 使用bool ,你必须#include <stdbool.h> .
  5. 您没有关闭 s_questions 的声明.

解决所有这些问题会给我们带来:

#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <time.h>

#define arrsize(a) (sizeof(a)/sizeof(a[0]))

struct Question
{
char quiz[130];
char answer1[20];
char answer2[20];
char answer3[20];
char answer4[20];
int correctAnswer;
bool used;
};

static struct Question s_questions[] = {
{
"Que significa la palabra 'ser'\n",
"1. to do",
"2. to be",
"3. to make",
"4. to understand",
2,
false
},
};

关于c - 我制作数组的方式有什么问题?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29543268/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com