코드 아래의 생성을 기반으로 파일 이름 : 대상 디렉토리, 라디오 방송국 이름과 현재 시간 :C에 공백없이 파일 이름을 생성
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;
}
출력 예 :
/home/ubuntu/Desktop/Europa FM_07042012-111705.ogg
문제 :
동일한 방송국 이름에는 제목에 공백이 포함될 수 있습니다.
Europa FM
Paprika Radio
Radio France Internationale
...........................
Rock FM
나는 그렇게되기 위해 생성 된 파일 이름 출력에서 공백을 제거하는 데 도움이 원하는 :
/home/ubuntu/Desktop/EuropaFM_07042012-111705.ogg
(더 복잡한 요구 사항은 모든 불법 문자를 제거하는 것. 파일 이름에서)
감사합니다.
UPDATE
이 작성하는 경우 :
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;
}
이 경고 가져 오기 :
경고 : '나 strlen'의 인수 하나를 전달하는 [기본적으로 활성화] 캐스트없이 정수의 포인터를 만드는 을 경고 : 캐스팅없이 정수에서 포인터를 할당합니다. [기본적으로 사용 가능]
왜 공백 문자를 파일 이름에 잘못된 문자로 간주합니까? – alk