Finale Anpassungen

This commit is contained in:
2020-03-22 13:33:37 +01:00
parent ebaf6a77f2
commit 50081506f3

17
main.c
View File

@@ -1,3 +1,9 @@
/**
* Implementierung des Programmentwurfs aus Programmieren 1
*
* Autoren: Simon Bestler und Johannes Freitag
* Das dritte Gruppenmitglied hat nicht am Projekt mitgewirkt und den Studiengang verlassen (Simeon Burk).
*/
#include <stdbool.h> #include <stdbool.h>
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
@@ -19,6 +25,13 @@
*/ */
#define MAX_FILE_PATH_LENGTH FILENAME_MAX #define MAX_FILE_PATH_LENGTH FILENAME_MAX
/**
* Formatierungsvorlage um den Dateipfad einzulesen.
* Die hier verwendete ANSI-C-kompatible Formatierung wird von der CodeBlocks MinGW-Version nicht unterstützt. In neueren Versionen von MinGW und allen anderen getesteten Compilern funktioniert das verwendete Format.
* Für CodeBlocks kann alternativ "%s" verwendet werden. Diese Formatierung ist aufgrund der nicht gegebenen Länge allerdings fehleranfällig.
*/
#define FILE_PATH_PATTERN "%" STR(MAX_FILE_PATH_LENGTH) "[^\n]"
/** /**
* Die maximal erlaubte Größe einer Matrix * Die maximal erlaubte Größe einer Matrix
*/ */
@@ -136,7 +149,7 @@ int main(int argc, char* argv[]) {
strncpy(filePath, argv[1], MAX_FILE_PATH_LENGTH); // Das erste Argument wird (auf MAX_FILE_PATH_LENGTH gekürzt) in filePath kopiert strncpy(filePath, argv[1], MAX_FILE_PATH_LENGTH); // Das erste Argument wird (auf MAX_FILE_PATH_LENGTH gekürzt) in filePath kopiert
} else { } else {
puts("Please enter the path of the file you'd like to open"); puts("Please enter the path of the file you'd like to open");
int result = scanf("%" STR(MAX_FILE_PATH_LENGTH) "[^\n]", filePath); // Liest MAX_FILE_PATH_LENGTH Zeichen aus der Konsole bis zum ersten Zeilenumbruch int result = scanf(FILE_PATH_PATTERN, filePath); // Liest MAX_FILE_PATH_LENGTH Zeichen aus der Konsole bis zum ersten Zeilenumbruch
if(result == EOF || result == 0 || filePath[0] == 0) { // Wenn Nichts gelesen werden konnte wird das Programm erfolgreich beendet if(result == EOF || result == 0 || filePath[0] == 0) { // Wenn Nichts gelesen werden konnte wird das Programm erfolgreich beendet
return 0; return 0;
} }
@@ -234,7 +247,7 @@ int main(int argc, char* argv[]) {
} }
puts("Enter file path or leave empty to exit"); puts("Enter file path or leave empty to exit");
int result = scanf("%" STR(MAX_FILE_PATH_LENGTH) "[^\n]", filePath); // Erneute Abfrage des Dateipfads int result = scanf(FILE_PATH_PATTERN, filePath); // Erneute Abfrage des Dateipfads
if(result == EOF || result == 0 || filePath[0] == 0) { // Wenn Eingabe leer ist if(result == EOF || result == 0 || filePath[0] == 0) { // Wenn Eingabe leer ist
goto end; goto end;
} }