thetrmite 2015-08-27 15:21 采纳率: 60%
浏览 3041

枚举类型输出无法输出字符串

#include

typedef enum {North, East, South, West} directionT;

directionT OppositeDirection(directionT dir)
{
switch(dir) {
case North: return (South);
case East: return (West);
case South: return (North);
case West: return (East);
}
}

int main()
{
printf("%s\n", OppositeDirection(North));
return 0;
}

运行后总是停止工作,然而我把printf("%s\n", OppositeDirection(North));改成
printf("%d\n", OppositeDirection(North));后却能显示正确的整型数值,但我想输出字符串啊,是哪里出问题了呢?

  • 写回答

3条回答 默认 最新

  • threenewbee 2015-08-27 15:26
    关注

    做不到。因为枚举对应的字符串根本在编译后的程序中就没有。
    只能再写switch case输出

    http://blog.chinaunix.net/uid-20412333-id-1950066.html

    评论

报告相同问题?

悬赏问题

  • ¥15 为什么我按照电路图做出的仿真和实物都不能使用
  • ¥15 mars2d在vue3中的引入问题
  • ¥50 h5唤醒支付宝并跳转至向小荷包转账界面
  • ¥15 算法题:数的划分,用记忆化DFS做WA求调
  • ¥15 chatglm-6b应用到django项目中,模型加载失败
  • ¥15 CreateBitmapFromWicBitmap内存释放问题。
  • ¥30 win c++ socket
  • ¥15 C# datagridview 栏位进度
  • ¥15 vue3页面el-table页面数据过多
  • ¥100 vue3中融入gRPC-web