Changed memory handling
This commit is contained in:
parent
33d9590acb
commit
1c16d83027
@ -4,7 +4,7 @@
|
|||||||
void header(int width, int margin, char lineChar, char *headerTitle, char *message);
|
void header(int width, int margin, char lineChar, char *headerTitle, char *message);
|
||||||
|
|
||||||
int main() {
|
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));
|
printf("%d\n", (int)strlen(message));
|
||||||
header(80, 4, '*', "Purpose", 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 ((contentWidth * rows) > (int)strlen(message)) { break; }
|
||||||
if (message[(contentWidth * rows)] != ' ') {
|
if (message[(contentWidth * rows)] != ' ') {
|
||||||
int i = 1;
|
int i = 1;
|
||||||
|
int tempCounter = 0;
|
||||||
while (1) {
|
while (1) {
|
||||||
printf("previous char = %c\n", message[(contentWidth * rows) - i]);
|
printf("previous char = %c\n", message[(contentWidth * rows) - i]);
|
||||||
if (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("start = %d\n", start);
|
||||||
printf("char after start = %c\n", message[start]);
|
printf("char after start = %c\n", message[start]);
|
||||||
int k = 0;
|
int k = 0;
|
||||||
for (int j = 0; j < (int)strlen(tempMessage); j++) {
|
for (int j = 0; j < (int)strlen(message); j++) {
|
||||||
tempMessage[j] = ' ';
|
tempMessage[j] = ' ';
|
||||||
}
|
}
|
||||||
for (int j = start; j < strlen(message); j++) {
|
for (int j = start; j < strlen(message); j++) {
|
||||||
tempMessage[k] = message[j];
|
tempMessage[k] = message[j];
|
||||||
|
tempCounter = k;
|
||||||
k++;
|
k++;
|
||||||
}
|
}
|
||||||
for (int j = 0; j < i; j++) {
|
for (int j = 0; j < i; j++) {
|
||||||
message[start + 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];
|
message[(start + i) + j] = tempMessage[j];
|
||||||
|
if (tempCounter + 1 == j) {
|
||||||
|
message[(start + i) + j] = 0;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -78,7 +83,7 @@ void header(int width, int margin, char lineChar, char *headerTitle, char *messa
|
|||||||
rows++;
|
rows++;
|
||||||
}
|
}
|
||||||
|
|
||||||
printf("%s\n", tempMessage);
|
printf("%c\n", message[230]);
|
||||||
printf("%s\n",message);
|
printf("%s\n",message);
|
||||||
|
|
||||||
printf("%s\n", topLine);
|
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++) {
|
for (int j = 0; j < contentWidth; j++) {
|
||||||
if (charCount == 0 && (message[j + (i * contentWidth)] == ' ')) {j++;}
|
if (charCount == 0 && (message[j + (i * contentWidth)] == ' ')) {j++;}
|
||||||
if (j + (i * contentWidth) == (int)strlen(message)) {
|
if (!(message[j + (i * contentWidth)])) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
printf("%c", message[j + (i * contentWidth)]);
|
printf("%c", message[j + (i * contentWidth)]);
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user