rtoax 2019-01-09 21:54 采纳率: 0%
浏览 2832

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

##1.问题描述

接口:

type strtotype(const char *stype);

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

##2.对比

有点类似于typeof

  • 写回答

3条回答 默认 最新

  • threenewbee 2019-01-10 00:12
    关注

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

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

    评论

报告相同问题?