C语言如何将字符串“int”转化为int类型

##1.问题描述

接口:

type strtotype(const char *stype);

其中type取值int、float等,stype取值“int”,“float”等。

##2.对比

有点类似于typeof

C语言没有泛型,没有办法了,只能用if分支
if (strcmp(stype, "int") == 0)
...
else if (strcmp(stype, "float") == 0)
...
else
printf("无法识别的类型");

返回类型也只能用void *,让调用者自己强转

这个似乎是没有办法的只能条件判断语句

字符串没有直接转化的工具,只能自己做