I have problems trying to copy one part of a string into a another. Given these two char pointers:
line points at string cointaining: "helmutDownforce:1234:44:yes"
username points at: NULL
Here's my function that takes these pointers as input:
char* findUsername(char* line, char* username){
char* ptr = strstr(line, ":");
ptrdiff_t index = ptr - line;
strncpy(username, line, index);
return username;
}
I get segmentation fault during strncpy. How come? The result I want is the function to return a pointer to a string containing helmutDownforce.