~smlavine/ascii-breakout

94701cc4f50873b2287a22a9516a2b273e47cb45 — Sebastian LaVine 5 months ago 68be0c2
Use heap allocation instead of arrays
1 files changed, 7 insertions(+), 5 deletions(-)

M main.c
M main.c => main.c +7 -5
@@ 633,14 633,14 @@ play(int level, unsigned int *score, int *lives)
void
showMessage(char *fmt, ...)
{
	/* Copy the fmt string into an array so that strtok() can work with it.
	 */
	char fmtCopy[strlen(fmt) + 1];
	strcpy(fmtCopy, fmt);
	char *fmtCopy, *line;

	/* We need to copy fmt because strtok() modifies its first argument. */
	fmtCopy = strdup(fmt);

	/* This will hold the (formatted) text that will be printed on each
	 * line before it is printed. */
	char line[WIDTH + 1];
	line = malloc(sizeof(*line) * (WIDTH + 1));

	/* Variables to handle the format arguments */
	int n;


@@ 699,6 699,8 @@ showMessage(char *fmt, ...)
	}

	va_end(ap);
	free(fmtCopy);
	free(line);
	fflush(stdout);
}