gpt4 book ai didi

c - 如何使用户输入调用函数 C

转载 作者:太空狗 更新时间:2023-10-29 16:05:50 24 4
gpt4 key购买 nike

我如何使用变量(从用户输入中获取)来调用函数?

char user_function[10];
scanf("%s", user_function);
user_function(); //Calls the function named user_function that the user typed

(没有这样的东西)

char user_function[10];
scanf("%s", user_function);
if( strcmp(user_function, 'printf()'))
printf();

最佳答案

你不能。

在某些时候,您必须查看字符串内容并使用它们来调用特定函数。

您可以通过查找表/字符串到函数指针的散列图来“隐藏”一点,但最终它仍然只是“查看字符串并决定调用什么”

关于c - 如何使用户输入调用函数 C,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41233491/

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