nt a Mayo pyramid with # characters depending on user input, i.e., the pyramid height h. To this end, update the size of the array for each level of the pyramid (for each for loop passing) using the realloc function. First of all, allocate an array for the first row. You need the allocate the memory for h + 2 characters for the first row. Fill it with spaces,
Language: C
Print a Mayo pyramid with # characters depending on user input, i.e., the pyramid height h. To this end, update the size of the array for each level of the pyramid (for each for loop passing) using the realloc function. First of all, allocate an array for the first row. You need the allocate the memory for h + 2 characters for the first row. Fill it with spaces, using the memset(row, ’ ’, h+2) command. For each row i, expand the array size to h + 4 + i, replace the last two characters of the line with # sign, followed by the string’s null terminator. That’s why you need increase the size by 2, with the respect to the original allocation, and then by 1 at each step. You also need to replace the space at the position h − 1 − i with the # character (the left slope of the pyramid). Print and examine your results, free the memory and use the valgrind function to check memory usage.
Step by step
Solved in 4 steps with 2 images