Answer the question
In order to leave comments, you need to log in
Why does strcat() stop the program?
C program stops execution at strcat() function
#include <stdio.h>
#include <stdlib.h>
int main(void)
{
int x = -1, z = 1;
char string[10] = { '\0' };
while (x != 0)
{
printf("Vvedit chislo = ");
scanf_s("%d", &x);
z = x * z;
strcat(string, z);
}
printf("%s\n", string);
_getch();
return 0;
}
Answer the question
In order to leave comments, you need to log in
Because you need to pass a pointer to a string to strcat, you pass the variable z as an int. As a result, z is interpreted as the address at which the string lies and a segmentation error occurs.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question