Thread: fopen() problems

  1. #1
    Registered User
    Join Date
    Jan 2005

    fopen() problems

    I'm using fopen to open a file in my program and I can't get the file to open for reading. Here's what I'm doing

     	if((*fp_in = fopen(filename_in, "r")) == NULL)
    	// display error message
    	printf("\nERROR: Input file not opened\n");
    	// abort
    filename_in is defined to "test_data.txt"
    This little snippet should open the file and test whether or not it was opened. since *fp_in is returned null, I get the "input file not opened" message. Where does the test_data.txt file need to be in order for this to work? i.e. same directory as source file or what? Thanks!

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    The edge of the known universe
    The first place it probably looks is the current directory.

    If you're running this in the debugger, you can usually set what the current directory will be, as far as the program is concerned.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  3. #3
    Registered User
    Join Date
    Jan 2005
    Got it to work. Thanks

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Having problems generating a video (.xyz)
    By JoeM in forum C Programming
    Replies: 3
    Last Post: 02-24-2009, 09:30 AM
  2. help with stat() and fopen()
    By movl0x1 in forum C Programming
    Replies: 6
    Last Post: 07-25-2007, 05:28 AM
  3. fopen help.
    By chriscolden in forum C Programming
    Replies: 17
    Last Post: 01-13-2006, 05:27 AM
  4. problem with fopen command
    By emon in forum C Programming
    Replies: 2
    Last Post: 03-11-2004, 11:11 PM
  5. fopen() and open()
    By Encrypted in forum C Programming
    Replies: 8
    Last Post: 02-09-2003, 03:57 PM
Website Security Test