60 lines
1.8 KiB
C
60 lines
1.8 KiB
C
/**
|
|
* Generic test class for implementing
|
|
* various functions for managing student data
|
|
* _ _ _ _
|
|
* __ ___ __(_) |_| |_ ___ _ __ | |__ _ _
|
|
* \ \ /\ / / '__| | __| __/ _ \ '_ \ | '_ \| | | |
|
|
* \ V V /| | | | |_| || __/ | | | | |_) | |_| |
|
|
* \_/\_/ |_| |_|\__|\__\___|_| |_| |_.__/ \__, |
|
|
* |___/
|
|
* ____ __ __ _
|
|
* / ___|_ _____ _ __ \ \ / /__ __ _ ___| |
|
|
* \___ \ \ / / _ \ '_ \ \ \ / / _ \ / _` |/ _ \ |
|
|
* ___) \ V / __/ | | | \ V / (_) | (_| | __/ |
|
|
* |____/ \_/ \___|_| |_| \_/ \___/ \__, |\___|_|
|
|
* |___/
|
|
* Licensed under the GPLv2 License, Version 2.0 (the "License");
|
|
* Copyright (c) Sven Vogel
|
|
*/
|
|
|
|
#include "options.h"
|
|
|
|
// name of the file to write to on --export
|
|
const char *FILE_NAME = "info_export.txt";
|
|
|
|
Student new_student(const char *name, const char *familyName, uint32_t matriculationNumber) {
|
|
Student new_stud = {
|
|
.name = name,
|
|
.familyName = familyName,
|
|
.matriculationNumber = matriculationNumber,
|
|
};
|
|
|
|
return new_stud;
|
|
}
|
|
|
|
/**
|
|
* @brief writes the format of student to the file specified by FILE_NAME.
|
|
*
|
|
* @param text
|
|
*/
|
|
void export_to_disk(const char* text) {
|
|
|
|
// open file in write mode only, truncating previous content to zero
|
|
FILE* handle = fopen(FILE_NAME, "w");
|
|
|
|
// file could not be opened
|
|
if (handle == NULL) {
|
|
fprintf(stderr, "could not open file to export\n");
|
|
return;
|
|
}
|
|
|
|
fprintf(handle, "%s", text);
|
|
|
|
fclose(handle);
|
|
|
|
printf("Author exported to disk. Goodbye!\n");
|
|
}
|
|
|
|
void generate_string(char *dest, const Student *student) {
|
|
sprintf(dest, "Name: %s %s, Matrikelnummer: %7d\n", student->name, student->familyName, student->matriculationNumber);
|
|
} |