I'm new to programming with C and I'm having problems with strings, pointers and structures. If someone could look at this code and tell me what's wrong, I'd greatly appreciate it.
Code:
struct FGrec_data{
char *input_file;
char *start_time;
char *stop_time;
char *output_file;
char *output_path;
};
int main(int argc, char *argv[])
{
struct FGrec_data FGdt;
parse_main_args(argc, argv, &FGdt);
......
}
int parse_main_args(int argc, char *argv[], struct FGrec_data *FGdata)
{
....
int i;
for(i = (strlen(FGdata->output_file)-2); i > 0; i--) {
if(FGdata->output_file[i] == 92) {
strncpy(FGdata->output_path, FGdata->output_file, i);
break;
}
}
//Why does this make my program crash?
....
....
}