These are some common questions that come up during this lab.
_CRT_SECURE_NO_WARNINGS
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:
_CRT_SECURE_NO_WARNINGS
to Project Properties > Configuration Properties > C/C++ > Preprocessor -> Preprocessor Definitions
.stdio.h
.#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
...
#pragma warning
before including stdio.h
.#pragma warning (disable : 4996)
#include <stdio.h>
...
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.
As the binary file is structured:
unsigned int
)char
array of variable length)unsigned int
)char
array of variable length)float
)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.
For queries relating to collaborating with the RSE team on projects: rse@sheffield.ac.uk
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.