Hey, I was wondering how one would go about checking what operating system the user was working in. That's allthanks
This is a discussion on Check Operating System within the C Programming forums, part of the General Programming Boards category; Hey, I was wondering how one would go about checking what operating system the user was working in. That's all ...
Hey, I was wondering how one would go about checking what operating system the user was working in. That's allthanks
Registered Linux User #380033. Be counted: http://counter.li.org
Standard C doesn't care about which OS you're on, so there is no standard way to find out. Not that this is much of a problem, since each OS has a different executable format (not to mention many different processor types), you can't just compile a bit of code and then expect it to execute on any machine.
When you compile the code, you typically have
Unfortunately, there is no standard naming convention for those defines.Code:#ifdef DOS /* code specific to DOS here */ #elifdef WIN32 /* code specific to Win32 here */ #elif LINUX /* code specific to Linux here */ #else #error Need another OS #endif
An alternative is to put all the non-portable code into
porting_dos.c
porting_win32.c
porting_linux.c
In either case, it's a good idea to minimise the amount of code in such places.
If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
If at first you don't succeed, try writing your phone number on the exam paper.
I support http://www.ukip.org/ as the first necessary step to a free Europe.
Alrighty, thanks.I was just wondering because in a program I'm writing / playing with, I want to clear the screen as the first thing i.e. windows: system("cls"); linux: system("clear"); but its not vital.. so thank you
![]()
Registered Linux User #380033. Be counted: http://counter.li.org