Guy
Guy

Reputation: 11

How I can check if a string is defined or not?

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

Answers (1)

unwind
unwind

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

Related Questions