fopen() problems

This is a discussion on fopen() problems within the C Programming forums, part of the General Programming Boards category; I'm using fopen to open a file in my program and I can't get the file to open for reading. ...

  1. #1
    Registered User
    Join Date
    Jan 2005
    Posts
    4

    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

    Code:
     	if((*fp_in = fopen(filename_in, "r")) == NULL)
    	{
    	// display error message
    	printf("\nERROR: Input file not opened\n");
    
    	// abort
    	exit(EXIT_FAILURE);
    	}
    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 wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,659
    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.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  3. #3
    Registered User
    Join Date
    Jan 2005
    Posts
    4
    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

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