fork download
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4.  
  5.  
  6. const int MAX_FILE_NAME = 254;
  7.  
  8.  
  9. const char *sys_file_name_from_usr_file_name(char *usr_file_name)
  10. {
  11. for(char * ptr = usr_file_name; *ptr != '\0'; ++ptr) {
  12. if ( *ptr == ' ' ) {
  13. *ptr = '_';
  14. }
  15. }
  16.  
  17. return usr_file_name;
  18. }
  19.  
  20. const char *usr_file_name_from_sys_file_name(char *sys_file_name)
  21. {
  22. for(char * ptr = sys_file_name; *ptr != '\0'; ++ptr) {
  23. if ( *ptr == '_' ) {
  24. *ptr = ' ';
  25. }
  26. }
  27.  
  28. return sys_file_name;
  29. }
  30.  
  31. int main(void)
  32. {
  33. char file_name[MAX_FILE_NAME];
  34.  
  35. printf( "Give me a file name: " );
  36. fgets( file_name, MAX_FILE_NAME, stdin );
  37.  
  38. printf( "\nSys file name: %s", sys_file_name_from_usr_file_name( file_name ) );
  39. printf( "\nUser file name: %s",
  40. usr_file_name_from_sys_file_name(
  41. sys_file_name_from_usr_file_name( file_name ) ) );
  42. return EXIT_SUCCESS;
  43. }
  44.  
Success #stdin #stdout 0s 5284KB
stdin
mi nombre de archivo.txt
stdout
Give me a file name: 
Sys file name: mi_nombre_de_archivo.txt
User file name: mi nombre de archivo.txt