c - 如何检查字符串是否已定义?
问题描述
我有如下代码。
我想检查一个字符串是否已定义或不使用isdefined
函数。
我该怎么做?
#include <stdio.h>
#include <stdbool.h>
#define string char*
bool isdefined(string str){
/*do something*/
}
int main(){
string hw; //print NO if I write this line
string hw = "Hello World"; //print YES if I write this line
if(isdefined(hw))
printf("YES");
else
printf("NO");
return 0;
}
解决方案
这是不可能的。
您所能做的就是检查它是否为,但不能NULL
保证将未初始化的自动变量设置为任何特定值,因此它不适用于您显示的代码。
“定义”在这里也不是正确的术语,它在 C 中意味着其他东西。
推荐阅读
- php - Woocommerce 基于重量的自定义运费计算
- python - 在 abc 范围内将移位的 ASCII 值转换为 char
- mysql - 在 MySQL 上将值拆分为多行
- spring-cloud - 如何在 Feign 中使用 http2 以获得更好的 RPC 性能?
- excel - 如何为 Excel 创建满足特定要求的唯一 ID
- spring - 发生错误时如何不使用 JMS 消息
- angular - 在 tomcat 上部署 Angular 6 应用程序
- machine-learning - 迁移学习完全不同的领域和任务
- systemd - 触发 systemd OnFailure 时如何获取进程的退出代码?
- marklogic - 如何从应用程序服务器运行 mlcp 导入林