From 1c16d8302776824034d65c26309ac38e79a600c9 Mon Sep 17 00:00:00 2001 From: garrett Date: Thu, 19 Sep 2024 10:26:09 -0400 Subject: [PATCH] Changed memory handling --- csci218/header.c | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/csci218/header.c b/csci218/header.c index a0f5a12..c2a97cb 100644 --- a/csci218/header.c +++ b/csci218/header.c @@ -4,7 +4,7 @@ void header(int width, int margin, char lineChar, char *headerTitle, char *message); int main() { - char message[] = "This program will calculate your BMI, Life Expectancy, and BSA(multiple methods) with just your weight(kg), height(cm), and gender."; + char message[] = "Testing this out some more. okay i think its working now DHOWEIFH HDSOIHTOHNDS HSODUIHT. This program will calculate your life expecantacy and bmi and BSA by just your weight(kg), height(cm), and gender."; printf("%d\n", (int)strlen(message)); header(80, 4, '*', "Purpose", message); @@ -48,6 +48,7 @@ void header(int width, int margin, char lineChar, char *headerTitle, char *messa if ((contentWidth * rows) > (int)strlen(message)) { break; } if (message[(contentWidth * rows)] != ' ') { int i = 1; + int tempCounter = 0; while (1) { printf("previous char = %c\n", message[(contentWidth * rows) - i]); if (message[(contentWidth * rows) - i] == ' ') { @@ -57,18 +58,22 @@ void header(int width, int margin, char lineChar, char *headerTitle, char *messa printf("start = %d\n", start); printf("char after start = %c\n", message[start]); int k = 0; - for (int j = 0; j < (int)strlen(tempMessage); j++) { + for (int j = 0; j < (int)strlen(message); j++) { tempMessage[j] = ' '; } for (int j = start; j < strlen(message); j++) { tempMessage[k] = message[j]; + tempCounter = k; k++; } for (int j = 0; j < i; j++) { message[start + j] = ' '; } - for (int j = 0; j < ((int)strlen(message)) - start - 1; j++) { + for (int j = 0; j < tempCounter + 2; j++) { message[(start + i) + j] = tempMessage[j]; + if (tempCounter + 1 == j) { + message[(start + i) + j] = 0; + } } break; } @@ -78,7 +83,7 @@ void header(int width, int margin, char lineChar, char *headerTitle, char *messa rows++; } - printf("%s\n", tempMessage); + printf("%c\n", message[230]); printf("%s\n",message); printf("%s\n", topLine); @@ -91,7 +96,7 @@ void header(int width, int margin, char lineChar, char *headerTitle, char *messa } for (int j = 0; j < contentWidth; j++) { if (charCount == 0 && (message[j + (i * contentWidth)] == ' ')) {j++;} - if (j + (i * contentWidth) == (int)strlen(message)) { + if (!(message[j + (i * contentWidth)])) { break; } printf("%c", message[j + (i * contentWidth)]);