I have a character array that will have a prefix and then a filename that will be between two square brackets. Something like this;
get[filename]
I need to isolate the characters between the brackets. Here is my attempt:
Code:
char* get_filename(char selection[]) {
char* ptr;
char* rv;
char* temp;
ptr = strtok(selection, "[");
ptr = strtok(NULL, "[");
strncpy(temp, ptr, sizeof(ptr));
ptr = strtok(temp, "]");
strncpy(rv, ptr, sizeof(ptr));
strcat(rv, "\0");
fprintf(stdout, "%s\n", rv);
return rv;
}
But of course, this isn't working. Can somebody please help me figure out what I am doing wrong? Thanks!