Basically I'm trying to print something like "1 2 3"
However, when I run this on a terminal, it gives me segmentation fault without any explanation...
#include <stdio.h>
#include <string.h>
int main() {
int width = 4;
char complete_row[width * 3 * 2];
char one[3], two[3], three[3], space[1];
strcpy(space, " ");
strcpy(complete_row, "");
int count = 0;
//make sure single line of color is replicated as much as width
while (count < width) {
strcpy(one, "1");
strcat(one, space);
strcpy(two, "2");
strcat(two, space);
strcpy(three, "3");
strcat(complete_row, one);
strcat(complete_row, two);
strcat(complete_row, three);
}
//print that twice in the output file
printf("%s", complete_row);
printf("%s", complete_row);
return 0;
}
strcpy(space, " ");you need room for the trailing\0: switch tospace[2]