如何在C条件preprocessor-指令比较两个字符串 [英] how to compare string in C conditional preprocessor-directives

查看:127
本文介绍了如何在C条件preprocessor-指令比较两个字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我必须做这样的事情在C,但如果我用一个char它只能工作,但我需要一个字符串
我该怎么办?

i have to do something like this in C but it works only if I use a char but I need a string how can I do?

#define USER "jack" // jack or queen

#if USER == "jack"
#define USER_VS "queen"
#elif USER == "queen"
#define USER_VS "jack"
#endif

感谢所有!

推荐答案

我不认为有办法做到可变长度的字符串比较完全preprocessor指令。你也许可以做到以下几点,但:

I don't think there is a way to do variable length string comparisons completely in preprocessor directives. You could perhaps do the following though:

#define USER_JACK 1
#define USER_QUEEN 2

#define USER USER_JACK 

#if USER == USER_JACK
#define USER_VS USER_QUEEN
#elif USER == USER_QUEEN
#define USER_VS USER_JACK
#endif

或者你也可以重构code一点点,采用C code来代替。

Or you could refactor the code a little and use C code instead.

这篇关于如何在C条件preprocessor-指令比较两个字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆