I'm going to do a complete rewrite my sad excuse of an emulator that doesn't even work and I'm having some trouble with opening the file. It should first open zenity (which works), then copy the output of zenity, which is the path to whatever file they chose, then parse the output and put backslashes in front of spaces (which works), but whenever I actually try to open the file (a file that does exist) it always fails, I looked around a bit more and found this so I commented out the
line but to no avail. Can anyone offer some advice as to what I'm doing wrong?
Code:
path[n++] = '\\';
Code:
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
char * select_file(void)
{
FILE *fp = popen("zenity --file-selection --title=\"Choose Gameboy Rom\"", "r");
static char path[1024];
memset(path, 0, sizeof(path));
if(fp == NULL)
{
printf("Failed to run command, make sure you have zenity installed!\n" );
exit(1);
}
fgets(path, sizeof(path), fp);
pclose(fp);
char path_copy[256];
strcpy(path_copy, path);
int n = 0;
for(int i = 0; i < sizeof(path); i++)
{
if(path_copy[i] == ' ')
{
path[n++] = '\\';
}
path[n++] = path_copy[i];
}
return path;
}
int main(void)
{
FILE * fp = NULL;
char file_to_open[1024];
strcpy(file_to_open, select_file());
printf("%s", file_to_open);
fp = fopen(file_to_open, "r");
if (fp == NULL)
{
perror("Error opening file: ");
}
return 0;
}