| | |
Own getchar function
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
The 3 Laws of the Procrastination Society:
1) Never do today that which can be put off until tomorrow
2) Tomorrow never comes
1) Never do today that which can be put off until tomorrow
2) Tomorrow never comes
It would have to be compiler and os specific which is why the C standards did not dictate how the function is to be implemented. You could use non-standard functions in conio.h like kbhit() and getch(), assuming your compiler supports those functions. For 32-bit programs that run under MS-Windows you could use the win32 api console functions. Don't know about MAC or *nix.
Don't PM me with questions -- you might get a nasty PM in response. If you have a question then post it in one of the forums.
•
•
Join Date: Dec 2006
Posts: 1,089
Reputation:
Solved Threads: 164
getc_unlocked() and getchar_unlocked() functions conform to IEEE Std 1003.1-2001
(POSIX.1). so every *nix (mac is *nix below the hood) should have them as part of the
base system. (in linux, it would be in glibc.)
"getc_unlocked() and getchar_unlocked()functions are equivalent to getc() & getchar()
respectively, except that the caller is responsible for locking the stream with
flockfile(3) before calling them. These functions may be used to avoid the
overhead of locking the stream for each character, and to avoid input being
dispersed among multiple threads reading from the same stream."
-- from freebsd man pages.
i guess most *nix implementations would implement getchar as
flockfile, getchar_unlocked, unflockfile
(POSIX.1). so every *nix (mac is *nix below the hood) should have them as part of the
base system. (in linux, it would be in glibc.)
"getc_unlocked() and getchar_unlocked()functions are equivalent to getc() & getchar()
respectively, except that the caller is responsible for locking the stream with
flockfile(3) before calling them. These functions may be used to avoid the
overhead of locking the stream for each character, and to avoid input being
dispersed among multiple threads reading from the same stream."
-- from freebsd man pages.
i guess most *nix implementations would implement getchar as
flockfile, getchar_unlocked, unflockfile
Last edited by vijayan121; Apr 8th, 2007 at 9:59 am. Reason: formatting
![]() |
Similar Threads
- bank system problem !!!! (C++ programming) (C++)
- query about getchar() (C++)
- How works EOF (C)
- help on 'Segmentation Fault' (C)
- reading a same input twice from the console (C)
Other Threads in the C++ Forum
- Previous Thread: From Vista to XP??
- Next Thread: Setting Cursor position
| Thread Tools | Search this Thread |
api application array arrays based beginner binary bitmap c++ c/c++ calculator char char* class classes coding compile compiler console conversion convert count data database delete desktop developer directshow dll dynamiccharacterarray email encryption error file forms fstream function functions game generator getline graph homeworkhelper iamthwee ifstream input int integer java lib linux list loop looping loops map math matrix memory multiple newbie news node number numbertoword output parameter pointer problem program programming project proxy python random read recursion recursive reference return rpg sorting string strings struct template templates text tree url vector video visual visualstudio win32 windows winsock word wordfrequency wxwidgets






