I have made this a simple command-line program which reads through a file and changes a few characters (ie, all "9" are replaces with "8"). It takes only a single argument, which is the input file. Now I want to make the output to be preceeded by a "_".
This is the code I came up with after reading about some string functions:
It works when calling "my_app my_file.txt" from the console, however when I drag and drop a file from Windows, the argument includes the full path, so I get something like argv = "C:\my_file.txt". When the "_" character is appended, the filename string is "_C:\my_file.txt", which crashes fopen, instead of "C:\_my_file.txt".Code:char * filename = malloc( strlen(argv) + 1); strcpy(filename, "_"); strcat(filename, argv); FILE *fp = fopen(filename, "wb"); /* Creates new file */
Can someone give a practical example how to deal with this? I'm not sure how to deal with this string modification.