MinGW is not really a well suited environment for C programming, but if your university course requires you to use it, then by all means ensure that you use it efficiently without letting it get in your way. Usually, MinGW comes with a (rather lousy) Windows port of the GNU Compiler Collection (GCC). Some IDEs use GCC via MinGW to invoke the GNU C compiler to compile C code. Here are some tips to ensure that your code is portable across different versions of Windows for your university C programming assignment:
Unsurprisingly, Microsoft had neglected their command line. For years, the default encoding for the command prompt was Code Page 437. This meant that only a limited character set could be displayed on it. It was not until Windows 10 that the default encoding changed to UTF-8. This presents some portability problems. From experience I can tell you that your lecturer will expect you to use the default settings on a specific version of Windows. To check the encoding on your command prompt, simply type the command chcp
and hit Enter. The output should be Active code page:
followed by the code page number. Please be aware that the encoding does affect your output.
Learn to use the Windows API via <windows.h>
for various functions such as setting the x- and y-coordinates of the console cursor and displaying coloured output. When referring to code online, try to identify if the solution is an OS-specific one. Certain C code for Linux may not work on Windows. Furthermore, some implementations of the C compiler may not support the functions and features you may want to use.
Compiling your code under the C standard ensures increased portability. However, the standard may cause you a bit of a hassle, especially when you have to consider that there are several versions of the standard, i.e. C89
, C99
and C11
. Ensure that your code adheres to the default standard on your IDE so that other people can compile it on another computer without having to mess around with the settings.