gpt4 book ai didi

c - 如何将一个数组中的特定字符串链接到另一个数组中的第二个字符串?

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

我现在完全迷失了。

我已经尝试了无数次让我的程序运行,但它就是不想运行。

快速概述:

我目前正在编写一个小词汇测验,它为用户提供一个随机的英语术语,用户必须用正确的德语术语来回答。测验结束后,会显示正确/错误答案的数量。

英语和德语术语都存储在二维数组中,我一生都无法弄清楚如何确保正确的德语术语固定到相应的英语单词。

代码如下:

#include <math.h>
#include <stdlib.h>
#include <stdio.h>
#include <assert.h>
#include <time.h>
#include <ctype.h>
#include <string.h>
#include <windows.h>


char eng[15][400]={"House","Lunatic","Nondescript","Ubiquity","Barley","Cardiac Arrest","Foreclosure",
"Thunderstorm","The answer to life, the universe and everything","Singularity"};
char ger[15][200]={"Haus","Irrer","nichtssagend","Allgegenwart","Gerste","Herzstillstand","Zwangsvollstreckung",
"Gewitter","42","Besonderheit"};
int i,corr=0,wrong=0,rnd, counter=0;
int choice[5];
int inArray;
char D[40];

int main(){

srand(time(NULL));

for(int i=0;i<5;i++) choice[i]=-1;

while(counter < 5){
rnd = rand()%10;
inArray = 0;

for(int i=0; i<5; i++){
if(choice[i] == rnd){
inArray = 1;
}
}
if(!inArray){
printf("\nQuestion number %d : %s\nPlease enter your answer: ", counter, eng[rnd]);
gets(D);

if(D==ger[rnd]){
corr++;
}
else{
wrong++;
}
choice[counter] = rnd;
counter++;
}
}
Sleep(1000);
printf("\n\n\n# of correct answers: %d\n# of false answers: %d",corr,wrong);


return 0;
getchar();
}

附录:我的正确/错误答案数量计数器似乎也被破坏了,对此有什么想法吗?

最佳答案

您可以尝试使用结构:

#include "stdio.h"

struct word {
char *eng;
char *ger;
};

struct word voc[] = {
{"House", "Haus"},
{"Lunatic", "Irrer"}
//etc...
};

int main() {
printf("%s %s\n", voc[1].eng, voc[1].ger);
return 0;
}

// Lunatic Irrer

(静态字符串使用字符指针)

关于c - 如何将一个数组中的特定字符串链接到另一个数组中的第二个字符串?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54526245/

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