gpt4 book ai didi

c - 如何从字符串数组中仅获取所需的元素

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

我有一个字符串数组,我只需要用户所需的元素。字符串数组如下:

 const char* string2[]={"•-","-•••", "-•-•","-••", "•", "••-•","--•","••••","••","•---","-•-","•-••",
"--","-•","---","•-•","--•-","•-•","•••","-","••-","•••-","•--","-••-",
"-•--","--••","•----","••---","•••--","••••-","•••••","-••••","--•••","---••",
"----•","-----"," "};

我创建了一个逻辑,从中我将能够获取用户所需的字符串数组的数量,但我无法获得正确的输出。问题是,例如我输入 Hello,我得到的数字如下:[8 5 12 12 15]

现在我希望输出为 string2[8]:••、string2[5]:••-• 等。

我需要做哪些改变才能让它发挥作用?

for(a[i]=0;a[i]<length;a[i++]){
printf("%s\t",string2[i]);
}

我已尝试使其正常工作,但无法提供帮助。

最佳答案

你可能想要这样的东西:

for(int i = 0; i < length; i++)
printf("%s\t", string2[a[i]]);

关于c - 如何从字符串数组中仅获取所需的元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44455362/

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