From 69e6c66704ef549349ace4fbb24693624577d134 Mon Sep 17 00:00:00 2001 From: Jason Peters Date: Wed, 31 Jan 2024 15:21:35 +0100 Subject: [PATCH] =?UTF-8?q?Zeilenumbr=C3=BCche=20in=20Array=20eingebaut=20?= =?UTF-8?q?und=20print=20hinzugef=C3=BCgt?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/c/Jason/ASCII_art.c | 20 ++++++++++++++++---- src/main/c/Jason/ASCII_art.h | 1 + 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/src/main/c/Jason/ASCII_art.c b/src/main/c/Jason/ASCII_art.c index d557b88..ea8f6fe 100644 --- a/src/main/c/Jason/ASCII_art.c +++ b/src/main/c/Jason/ASCII_art.c @@ -21,8 +21,9 @@ void quadrat(){ char Quadrat[arraySize]; befuellenDesArraysMitX(Quadrat, arraySize); befuelleArrayMitLeerzeichen(Quadrat, arraySize); + befuelleArrayMitZeilenumbruechen(Quadrat,groesse); - + printf("\n%s", Quadrat); } @@ -37,7 +38,7 @@ return 0; void auswahlDerArt(int pick){ switch (pick) { case (1): - return quadrat(); + quadrat(); break; case (2): @@ -79,7 +80,18 @@ void befuelleArrayMitLeerzeichen(char quadraT[], int laenge){ if(i % 2 != 0){ quadraT[i] = ' '; } - } quadraT[laenge-1] = '\0'; -} \ No newline at end of file +} + +void befuelleArrayMitZeilenumbruechen(char quadraT[], int laenge){ + + int zeile = 2 * laenge; + int laengeGesamt = zeile * laenge; + for (int i = 0; i < laengeGesamt; i++){ + if((i + 1) % zeile == 0){ + quadraT[i] = '\n'; + } + } + quadraT[laengeGesamt-1] = '\0'; +} diff --git a/src/main/c/Jason/ASCII_art.h b/src/main/c/Jason/ASCII_art.h index 61dca6a..e41f8a0 100644 --- a/src/main/c/Jason/ASCII_art.h +++ b/src/main/c/Jason/ASCII_art.h @@ -9,6 +9,7 @@ int frageNachGroesse(); int berechnungDerLaengeDesQuadratArrays(int); void befuellenDesArraysMitX(char[], int); void befuelleArrayMitLeerzeichen(char[],int); +void befuelleArrayMitZeilenumbruechen(char[],int);