diff --git a/main.c b/main.c index c84ae08..5ba1cfc 100644 --- a/main.c +++ b/main.c @@ -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 #include #include @@ -19,6 +25,13 @@ */ #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 */ @@ -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 } else { 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 return 0; } @@ -234,7 +247,7 @@ int main(int argc, char* argv[]) { } 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 goto end; }