create file on desktop c++

Discussion in 'Mac Programming' started by kay.altos, Dec 27, 2007.

  1. kay.altos macrumors newbie

    Joined:
    Dec 27, 2007
    #1
    in c++ trying to do it this way, but it doesen't help

    int logA = 0;
    FILE* f = fopen("~/Desktop/rr.log","w");
    int a = errno;
    fprintf(f,"%d", ++logA);
    fclose(f);

    errno returns 2 - "No such file or directory", there is no file present but it should be created.

    please advise
     
  2. AlmostThere macrumors 6502a

    #2
    use a fully qualified path ("/Users/yourname/Desktop/rr.log") or import environment variables to get $HOME (use getenv from cstdlib or stdlib.h if you are using C, type "man 3 getenv" in Terminal to see usage)
     
  3. kay.altos thread starter macrumors newbie

    Joined:
    Dec 27, 2007

Share This Page