Reputation: 11
I have codes as below.
I wanna check if a string is defined or not using isdefined
function.
How I do that?
#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;
}
Upvotes: 0
Views: 237
Reputation: 400029
That is not possible.
All you can do is check for it not being NULL
, but an un-initialized automatic variable is not guaranteed to be set to any particular value so it won't work for the code you've shown.
Also "defined" is not the proper term here, it means something else in C.
Upvotes: 2