#include <stdio.h>
#include <stdlib.h>
#include <string.h>
const int MAX_FILE_NAME = 254;
const char *sys_file_name_from_usr_file_name(char *usr_file_name)
{
for(char * ptr = usr_file_name; *ptr != '\0'; ++ptr) {
if ( *ptr == ' ' ) {
*ptr = '_';
}
}
return usr_file_name;
}
const char *usr_file_name_from_sys_file_name(char *sys_file_name)
{
for(char * ptr = sys_file_name; *ptr != '\0'; ++ptr) {
if ( *ptr == '_' ) {
*ptr = ' ';
}
}
return sys_file_name;
}
int main(void)
{
char file_name[MAX_FILE_NAME];
printf( "Give me a file name: " ); fgets( file_name
, MAX_FILE_NAME
, stdin
);
printf( "\nSys file name: %s", sys_file_name_from_usr_file_name
( file_name
) ); printf( "\nUser file name: %s", usr_file_name_from_sys_file_name(
sys_file_name_from_usr_file_name( file_name ) ) );
return EXIT_SUCCESS;
}
I2luY2x1ZGUgPHN0ZGlvLmg+CiNpbmNsdWRlIDxzdGRsaWIuaD4KI2luY2x1ZGUgPHN0cmluZy5oPgoKCmNvbnN0IGludCBNQVhfRklMRV9OQU1FID0gMjU0OwoKCmNvbnN0IGNoYXIgKnN5c19maWxlX25hbWVfZnJvbV91c3JfZmlsZV9uYW1lKGNoYXIgKnVzcl9maWxlX25hbWUpCnsKCWZvcihjaGFyICogcHRyID0gdXNyX2ZpbGVfbmFtZTsgKnB0ciAhPSAnXDAnOyArK3B0cikgewoJCWlmICggKnB0ciA9PSAnICcgKSB7CgkJCSpwdHIgPSAnXyc7CgkJfQoJfQoJCglyZXR1cm4gdXNyX2ZpbGVfbmFtZTsKfQoKY29uc3QgY2hhciAqdXNyX2ZpbGVfbmFtZV9mcm9tX3N5c19maWxlX25hbWUoY2hhciAqc3lzX2ZpbGVfbmFtZSkKewoJZm9yKGNoYXIgKiBwdHIgPSBzeXNfZmlsZV9uYW1lOyAqcHRyICE9ICdcMCc7ICsrcHRyKSB7CgkJaWYgKCAqcHRyID09ICdfJyApIHsKCQkJKnB0ciA9ICcgJzsKCQl9Cgl9CgkKCX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