int main() {
char WORDS[10][20] = { "Apple","Banana","Cucumber","Dumpling","Eggplant","Fish","Garlic","Ham","Icecream","Jellies" };
//这里运用到了二维数组的知识,对题库进行一个存储。
int num;
printf("Enter the number of words to guess (<=10):");
scanf("%d", &num);
int count[num];
int i;
在部分编译器中,不允许使用变量定义数组的大小,所以int count[num];这里就会报错。
有两种修改方法:
一是:定义一个大数组,如: int count[10000]; 实际用的时候只用num个。
二是:使用malloc申请空间,如下:
#include <stdlib.h>
int* count = (int*)malloc(sizeof(int)*num); //coun可以像数组一样使用,如count[0]
//使用malloc()需要包含头文件stdlib.h
代码不全?
粘贴一下完整代码和对应报错看看