Segmentation fault (core dumped) в strcat - C (СИ)
Формулировка задачи:
Сделал программу, в с новичок, но при вызове strcat выдоет ошибку: "Segmentation fault (core dumped)" Что не так? Заранее спс
#include <stdio.h>
#include <cs50.h>
#include <string.h>
int main (void) {
int height;
do {
printf("height: ");
height = GetInt();
} while (!((height > 0) && (height < 23)));
for (int i = 0;i < height;i++){
char *lattice = "##";
printf("%s\n", lattice);
strcat(lattice, "#");
}
return 0;
}Решение задачи: «Segmentation fault (core dumped) в strcat»
textual
Листинг программы
#include <stdio.h>
#include <cs50.h>
#include <string.h>
int main (void) {
int height;
int i;
char lattice[22] = {'#', '#'};
do {
printf("height: ");
scanf("%d", &height);
} while (!((height > 0) && (height < 23)));
for ( i= 0;i < height;i++){
printf("%s\n", lattice);
strcat(lattice, "#");
}
return 0;
}