COM4521/COM6521: Lab 2 FAQ

Lab 2 - FAQ

These are some common questions that come up during this lab.


The IO functions provided by stdio.h are considered ‘unsafe’ as they take buffers without knowing the buffer’s length, which may allow the function to write beyond the end of the buffer.

Microsoft has safe version of these functions, which it enforces use of by default, however they are not cross-platform (compatible with Linux/GCC) so we don’t use them.

There are 3 ways to suppress this warning/error:

  • Add _CRT_SECURE_NO_WARNINGS to Project Properties > Configuration Properties > C/C++ > Preprocessor -> Preprocessor Definitions.
  • Define the macro before including stdio.h.
#include <stdio.h>
  • Tell the compiler to disable the warning by using #pragma warning before including stdio.h.
#pragma warning (disable : 4996)
#include <stdio.h>

students.bin was not found

Files listed within Visual Studio’s Solution Explorer do not correspond to the file structure on disk. If you are specifying a file location with a relative path e.g. "students.bin", at runtime your code will only look in the working directory.

By default visual studio uses your project’s directory as the working directory. You can locate the project’s folder, by right clicking your project in the Solution Explorer and selecting “Open Folder in File Explorer”.

It’s also recommended that you move all your source files into this folder or a subdirectory, and specify all includes relative to this directory.

Ex 2: The values are loaded incorrectly

As the binary file is structured:

  1. Forename Length (unsigned int)
  2. Forename (char array of variable length)
  3. Surname Length (unsigned int)
  4. Surname (char array of variable length)
  5. Module mark (float)
  6. Repeated per student

It’s important to read all 5 components, per student, in order. If you only read the forename and surname, then the file reading will be out of sync, meaning that all data read after the first surname will be misaligned. This could lead to the data read into the char arrays not containing a null terminating character, which may cause any access violation when attempting to print it.

Contact Us

For queries relating to collaborating with the RSE team on projects:

Information and access to JADE II and Bede.

Join our mailing list so as to be notified when we advertise talks and workshops by subscribing to this Google Group.

Queries regarding free research computing support/guidance should be raised via our Code clinic or directed to the University IT helpdesk.