opening a file to read

This is a discussion on opening a file to read within the C Programming forums, part of the General Programming Boards category; this is just a quick question should be easy... but if im opening a file to be read in like ...

  1. #1
    Registered User
    Join Date
    Sep 2007
    Posts
    16

    opening a file to read

    this is just a quick question should be easy... but if im opening a file to be read in like input.txt where do i put the input.txt file?

  2. #2
    Chinese pâté foxman's Avatar
    Join Date
    Jul 2007
    Location
    Canada
    Posts
    404
    You put it in the same directory as your executable. Should be fine in most of the cases, except if you are drog and drapping file on your executable (in Windows) where you'll now need the complete path (ex. "C:/a_folder/my_file.txt") to reach the correct file....

  3. #3
    Registered User
    Join Date
    Sep 2007
    Posts
    16
    worked great thanks i thought thats where it needed to go but for some odd reason it wasnt working fiddled with it now it does thanks!

  4. #4
    Registered User
    Join Date
    Sep 2006
    Posts
    230
    Actually, you don't have to put it in the same directory. You're supposed to give it the full path. But if fopen does only finds a file name with no path, then it searches it's current directory.

    e.g. If the file called text.txt and is placed in C:\ you can either open it with
    Code:
    fopen("C:\\text.txt", "r");
    Note that '\\' is needed since \ is used as an escape sequence.

    OR you can place the file in C:\ and run it with
    Code:
    fopen("text.txt", "r");
    Hope I helped

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Newbie homework help
    By fossage in forum C Programming
    Replies: 3
    Last Post: 04-30-2009, 05:27 PM
  2. C++ std routines
    By siavoshkc in forum C++ Programming
    Replies: 33
    Last Post: 07-28-2006, 01:13 AM
  3. Possible circular definition with singleton objects
    By techrolla in forum C++ Programming
    Replies: 3
    Last Post: 12-26-2004, 10:46 AM
  4. c script help to read a file & update
    By indy in forum C Programming
    Replies: 8
    Last Post: 12-01-2003, 11:32 AM
  5. System
    By drdroid in forum C++ Programming
    Replies: 3
    Last Post: 06-28-2002, 11:12 PM

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