fork download
  1. // C program to detect Operating System
  2.  
  3. #include <stdio.h>
  4.  
  5. // Driver Code
  6. int main()
  7. {
  8.  
  9. // Checking for windows OS with
  10. // _WIN32 macro
  11. #ifdef _WIN32
  12. printf("Hey Geek it seems that"
  13. "you are working on a Windows OS.\n");
  14.  
  15. // Checking for mac OS with
  16. // __APPLE__ macro
  17. #elif __APPLE__
  18. printf("Hey Geek it seems that you"
  19. "are working on a Mac OS.\n");
  20.  
  21. // Checking for linux OS with
  22. // __linux__ macro
  23. #elif __linux__
  24. printf("Hey Geek it seems that you"
  25. "are working on a Linux OS.\n");
  26.  
  27. // Checking for iOS embedded OS with
  28. // TARGET_OS_EMBEDDED macro
  29. #elif TARGET_OS_EMBEDDED
  30. printf("Hey Geek it seems that you"
  31. "are working on an iOS embedded OS.\n");
  32.  
  33. // Checking for iOS simulator OS with
  34. // TARGET_IPHONE_SIMULATOR macro
  35. #elif TARGET_IPHONE_SIMULATOR
  36. printf("Hey Geek it seems that you"
  37. "are working on an iOS simulator OS.\n");
  38.  
  39. // Checking for iPhone OS with
  40. // TARGET_OS_IPHONE macro
  41. #elif TARGET_OS_IPHONE
  42. printf("Hey Geek it seems that you"
  43. "are working on an iPhone OS.\n");
  44.  
  45. // Checking for MAC OS with
  46. // TARGET_OS_MAC macro
  47. #elif TARGET_OS_MAC
  48. printf("Hey Geek it seems that you"
  49. "are working on a MAC OS.\n");
  50.  
  51. // Checking for Android OS with
  52. // __ANDROID__ macro
  53. #elif__ANDROID__
  54. printf("Hey Geek it seems that you"
  55. "are working on an android OS.\n");
  56.  
  57. // Checking for unix OS with
  58. // __unix__ macro
  59. #elif __unix__
  60. printf("Hey Geek it seems that you"
  61. "are working on a unix OS.\n");
  62.  
  63. // Checking for POSIX based OS with
  64. // _POSIX_VERSION macro
  65. #elif _POSIX_VERSION
  66. printf("Hey Geek it seems that you"
  67. "are working on a POSIX based OS.\n");
  68.  
  69. // Checking for Solaris OS with
  70. // __sun macro
  71. #elif __sun
  72. printf("Hey Geek it seems that you"
  73. "are working on a Solaris OS.\n");
  74.  
  75. // Checking for HP UX OS with
  76. // __hpux macro
  77. #elif __hpux
  78. printf("Hey Geek it seems that you"
  79. "are working on a HP UX OS.\n");
  80.  
  81. // Checking for BSD OS with
  82. // BSD macro
  83. #elif BSD
  84. printf("Hey Geek it seems that you"
  85. "are working on a Solaris OS.\n");
  86.  
  87. // Checking for DragonFly BSD OS with
  88. // __DragonFly__ macro
  89. #elif __DragonFly__
  90. printf("Hey Geek it seems that you"
  91. "are working on a DragonFly BSD OS.\n");
  92.  
  93. // Checking for FreeBSD OS with
  94. // __FreeBSD__ macro
  95. #elif __FreeBSD__
  96. printf("Hey Geek it seems that you"
  97. "are working on a FreeBSD OS.\n");
  98.  
  99. // Checking for Net BSD OS with
  100. // __NetBSD__ macro
  101. #elif __NetBSD__
  102. printf("Hey Geek it seems that you"
  103. "are working on a Net BSD OS.\n");
  104.  
  105. // Checking for Open BSD OS with
  106. // __OpenBSD__ macro
  107. #elif __OpenBSD__
  108. printf("Hey Geek it seems that you"
  109. "are working on an Open BSD OS.\n");
  110.  
  111. // If neither of them is present
  112. // then this is printed...
  113. #else
  114. printf("Sorry, the system are"
  115. "not listed above.\n");
  116. #endif
  117. return 0;
  118. }
  119.  
Success #stdin #stdout 0s 5396KB
stdin
Standard input is empty
stdout
Hey Geek it seems that youare working on a Linux OS.