Does getchar_unlocked fn works in code blocks..??

hii friends…i am new here… help me plz…

I am using getchat_unlocked fn in codeblocks… and it is not working there…!! why??

Quoting from this ANSWER

"getchar_unlocked is deprecated in Windows because it is thread unsafe version of getchar()"

So if you are using windows,it doesn’t matter which IDE you use,you’ll get error.But if you are using linux, it should work properly.
In windows instead of getchar_unlocked() you can use getchar(),it’ll do the same thing. You can edit this to the uploaded version.


Use this instead

#define gc getchar_unlocked


#define gc getchar


Brother, getchar_unlocked is not a C/C++ standard function. It’s a POSIX standard & Windows compilers don’t support all POSIX functions.
If you replace getchar_unlocked with getchar, it will work.
If you still want to use it then go for conditional compilation as follows : -

#ifdef _WINDOWS
// no getchar_unlocked on Windows so just call getchar
inline int getchar_unlocked() { return getchar(); }
1 Like