fopen to right Directory

This is a discussion on fopen to right Directory within the C Programming forums, part of the General Programming Boards category; Hi all, i want to create a file temp.txt in the E:/Route400/amlv1 folder. On running this code the file always ...

  1. #1
    Registered User
    Join Date
    Mar 2003
    Posts
    28

    Angry fopen to right Directory

    Hi all,

    i want to create a file temp.txt in the E:/Route400/amlv1 folder.

    On running this code the file always lands up in E:/Route400/ and not E:/Route400/amlv1

    Any probelm with the fopen statement ?? any other way to specify path ??




    ====================================
    system("E:");
    system("cd\\");
    system("cd route400");
    system("cd amlv1");
    fp3=fopen("temp.txt","w");
    fprintf(fp3,"%s",a);
    fclose(fp3);
    fflush(fp3);
    system("cd\\");
    system("c:");

  2. #2
    Registered User
    Join Date
    Mar 2003
    Posts
    28
    thanks; but on executing the edate.exe and edate.obj files land in E:\route400\amlv1

    Why ?? (edate.c is the name of file)

  3. #3
    eh ya hoser, got a beer? stumon's Avatar
    Join Date
    Feb 2003
    Posts
    323
    Originally posted by compiler
    thanks; but on executing the edate.exe and edate.obj files land in E:\route400\amlv1

    Why ?? (edate.c is the name of file)
    That is compiler specific. Each compiler will always put the exe someplace different. If you do what salem says, it doesn't matter where the exe file it will always try to open that file in that location, or with the "w" it will create/over write whats there.
    The keyboard is the standard device used to cause computer errors!

  4. #4
    Registered User
    Join Date
    Mar 2003
    Posts
    28
    !!
    Or do it like this and save all the hassle
    Or do it like this and save all the hassle
    fp3=fopen("e:\\route400\\amlv1\\temp.txt","w");

    This too does not solve the initial probelm, the file temp.txt still lands in E:\Route400 and anot E:\route400\amlv1

  5. #5
    Registered User
    Join Date
    Mar 2003
    Posts
    28
    Win NT, Turbo C

    i think i got it; the compiler is dumping the exe in the active directory on compilation. Since the code was switching between many directories on different drives the exe used to land elsewhere.

    Thanks a ton.

  6. #6
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    Posts
    6,231
    This maybe a little OT, but ..... If you're after a temporary file, you might also want to look at the tmpfile() function.
    http://www.rt.com/man/tmpfile.3.html
    When all else fails, read the instructions.
    If you're posting code, use code tags: [code] /* insert code here */ [/code]

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Profiler Valgrind
    By afflictedd2 in forum C++ Programming
    Replies: 4
    Last Post: 07-18-2008, 09:38 AM
  2. Couple errors please help :-D
    By JJJIrish05 in forum C Programming
    Replies: 9
    Last Post: 03-06-2008, 01:54 AM
  3. Replies: 1
    Last Post: 12-10-2007, 05:26 PM
  4. Replies: 6
    Last Post: 07-30-2003, 03:08 AM
  5. Directory reading trouble
    By samGwilliam in forum Linux Programming
    Replies: 0
    Last Post: 03-10-2002, 08:43 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21