"segmentation fault: 11" with sprintf in C
Hi,
I have problems with the strings size. My program is the following: Code:
#include <stdio.h> I noticed that changing the size of the input array from 20 to (at least) 41 solves the problem and sprintf works as well. Why? |
Hi.
Quote:
You should allocate a big enough buffer before trying to write to it: Code:
char *str = malloc(sizeof(char)*20); Code:
char str[20]; // static allocation Quote:
Few links: C pointers and arrays, C memory management. |
It is true.
Thanks a lot! |
All times are GMT -5. The time now is 09:54 PM. |