Hello, guys! I'm trying to get a substring of a string in C and i'm using strncpy function to do this. The compilation doesn't show any error message, but when i try to run the program, i have a "Segmentation fault" error message in terminal! I'm using Debian with Gcc-4.7.
First of all pointers to string literal should be declared with the const qualifier because neither C nor C++ allow to modify string literals.
So instead of
char *time = "09:34";
there should be written
const char *time = "09:34";
Secondly both of you are trying to copy the original string literal to a memory with an arbitrary address becuase neither min nor temp were properly initialized.