C - file not opening

Discussion in 'Computer Programming, Emulation, and Game Modding' started by Monado_III, Jul 13, 2016.

  1. Monado_III
    OP

    Monado_III GBAtemp Advanced Fan

    Member
    637
    352
    Feb 8, 2015
    Canada
    /dev/null
    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
    Code:
    path[n++] = '\\';
    line but to no avail. Can anyone offer some advice as to what I'm doing wrong?
    code
     
  2. TheZoc

    TheZoc GBAtemp Regular

    Member
    234
    21
    Apr 6, 2009
    Brazil
    Rio de Janeiro
    From the looks of it, your code reminds me of unix/linux code, yet you're using windows paths.

    Try using '/' in place of '\\' and see if it works ;)
     
  3. Monado_III
    OP

    Monado_III GBAtemp Advanced Fan

    Member
    637
    352
    Feb 8, 2015
    Canada
    /dev/null
    the '\'s are for spaces (think escape sequences), the actually path that you get from printf is something like /home/*user*/somedir/some\ file.txt, I'm not sure if the backslashes are needed in C but it doesn't seem to make a difference as nothing opens either way
     
    Last edited by Monado_III, Jul 13, 2016
  4. spoonm

    spoonm Can count to 3.

    Member
    174
    84
    May 20, 2015
    Brazil
    The escape slashes are not needed. I just created a file called "test file" with the contents:

    Code:
    Can I open this file? Can I?
    Will it fail, my while?
    
    I like coconut water.
    , then wrote, compiled and ran the following:

    Code:
    #include <stdio.h>
    #include <stdlib.h>
    
    int
    main(void)
    {
        FILE *fp = NULL;
        int c;
    
        if ((fp = fopen("test file", "r")) == NULL)
        {
            perror("Error opening file");
            exit(1);
        }
    
        while ((c = fgetc(fp)) != EOF)
            putchar(c);
    
        fclose(fp);
    
        return EXIT_SUCCESS;
    }
    And it's worked fine:

    [​IMG]
     
    Last edited by spoonm, Jul 17, 2016
    Monado_III likes this.