The code below generate file name based on: destination directory, radio station name and current time:
static int start_recording(const gchar *destination, const char* station, const char* time)
{
Recording* recording;
char *filename;
filename = g_strdup_printf(_("%s/%s_%s"),
destination,
station,
time);
recording = recording_start(filename);
g_free(filename);
if (!recording)
return -1;
recording->station = g_strdup(station);
record_status_window(recording);
run_status_window(recording);
return 1;
}
output example:
/home/ubuntu/Desktop/Europa FM_07042012-111705.ogg
Problem:
Same station name may contain white space in title:
Europa FM
Paprika Radio
Radio France Internationale
...........................
Rock FM
I want to help me to remove whitespace from generated filename
output to become so:
/home/ubuntu/Desktop/EuropaFM_07042012-111705.ogg
(a more complex requirement would to eliminate all illegal char. from filename)
Thank you.
UPDATE
If write this:
static int start_recording(const gchar *destination, const char* station, const char* time)
{
Recording* recording;
char *filename;
char* remove_whitespace(station)
{
char* result = malloc(strlen(station)+1);
char* i;
int temp = 0;
for( i = station; *i; ++i)
if(*i != ' ')
{
result[temp] = (*i);
++temp;
}
result[temp] = '\0';
return result;
}
filename = g_strdup_printf(_("%s/%s_%s"),
destination,
remove_whitespace(station),
time);
recording = recording_start(filename);
g_free(filename);
if (!recording)
return -1;
recording->station = g_strdup(station);
tray_icon_items_set_sensible(FALSE);
record_status_window(recording);
run_status_window(recording);
return 1;
}
Get this warning:
warning: passing argument 1 of ‘strlen’ makes pointer from integer without a cast [enabled by default]
warning: assignment makes pointer from integer without a cast [enabled by default]
Removes spaces, new lines, tabs, carriage return etc.
Note that this also copies the null termination character.