fopen returning "Bad File Pointer"

This is a discussion on fopen returning "Bad File Pointer" within the C Programming forums, part of the General Programming Boards category; my code will work if an invalid file is typed, but if it receives a valid file it gives me ...

  1. #1
    Registered User
    Join Date
    Apr 2009
    Posts
    3

    Question fopen returning "Bad File Pointer"

    my code will work if an invalid file is typed, but if it receives a valid file it gives me a non-"NULL" file pointer that is apparently "bad."

    Visual Studio watch:
    fp: 0x0042dbd0 {_ptr=0x00000000 <Bad Ptr> _cnt=0 _base=0x00000000 <Bad Ptr> ...} _iobuf *

    note that the value of fp isn't 0 any more, but everything within it is "bad."

    Code:
    int main()
    {
    	FILE *fp = NULL;
    	char fileIn[80] = {0};
            int k;
    	printf("\nPlease enter the name of the file  ");
    	while( fp == NULL )
    	{
    		scanf("%s", fileIn);
    		if( ( k = strcmp(fileIn, "QUIT") ) == 0 )
    		{
    			printf(" \n Good Bye.");
    			getchar();
    			return 0;
    		}
    		if( (fp = fopen(fileIn, "r")) == NULL )
    		{
    			printf("\n\nError: File not found.");
    			printf("\nType QUIT to exit or try a valid file name.");
    		}		
    	}
    	getchar(); /* pause for user */
    	return 0;
    }
    any ideas???

    thanks

  2. #2
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    What do you mean it's bad? You aren't doing anything with it. Why is it you think it's bad?


    Quzah.
    Hope is the first step on the road to disappointment.

  3. #3
    Registered User
    Join Date
    Apr 2009
    Posts
    3
    I do use it. the watch says that the file doesn't have anything in it but that is false. i use fscanf to read in a value and it makes the program crash. the error says "R6002 - floating point not loaded"
    Last edited by jprukop; 04-17-2009 at 02:54 PM.

  4. #4
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    That's not a bad pointer error, that's a "Hey, the floating point library isn't loaded." error. Try adding a floating point number where you actually declare a floating point number, and initialize it to something first.


    Quzah.
    Hope is the first step on the road to disappointment.

  5. #5
    Registered User
    Join Date
    Apr 2009
    Posts
    3
    alrighty. thanks a ton. that was stupid of me.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. A development process
    By Noir in forum C Programming
    Replies: 37
    Last Post: 07-10-2011, 10:39 PM
  2. Newbie homework help
    By fossage in forum C Programming
    Replies: 3
    Last Post: 04-30-2009, 04:27 PM
  3. C++ std routines
    By siavoshkc in forum C++ Programming
    Replies: 33
    Last Post: 07-28-2006, 12:13 AM
  4. Replies: 3
    Last Post: 03-04-2005, 01:46 PM
  5. System
    By drdroid in forum C++ Programming
    Replies: 3
    Last Post: 06-28-2002, 10:12 PM

Tags for this Thread


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