Thread: new to file handling!

  1. #1
    Registered User
    Join Date
    Oct 2004
    Posts
    32

    new to file handling!

    the following code which just displays file contents compiles successfully but give runtime error!!

    Code:
    #include <stdio.h>
    
    int main() 
    { 
    	FILE  *fp; 
    	int c ; 
    
    	fp = fopen( "hp.txt","r" ); 
    	c = getc( fp ) ; 		
    	while (  c != EOF ) 
    	{
    		putchar( c ); 		
    		c = getc ( fp ); 	 
    	}
    
    	fclose( fp ); 
    	return 0;
    }

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,661
    One can only guess what error you're seeing.

    My guess, it didn't open the file, since you didn't check for that
    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
    Oct 2004
    Posts
    32
    actually while executing it says .exe file has encountered problems and need to close.

  4. #4
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,661
    Well young grasshopper, did you add the error checks?
    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.

  5. #5
    Registered User
    Join Date
    Oct 2004
    Posts
    32
    dont be angry sir !
    this problem is coming with dev c++ but with turbo c++, what could be causing this
    const.exe is a another problem giving the same error.

    error signature
    AppName: const.exe AppVer: 0.0.0.0 ModName: const.exe
    ModVer: 0.0.0.0 Offset: 000012ca

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Creating File Handling Functions
    By td4nos in forum C Programming
    Replies: 6
    Last Post: 06-26-2009, 11:43 AM
  2. basic file handling problem
    By georgen1 in forum C Programming
    Replies: 4
    Last Post: 03-05-2009, 06:21 AM
  3. gcc link external library
    By spank in forum C Programming
    Replies: 6
    Last Post: 08-08-2007, 03:44 PM
  4. Batch file programming
    By year2038bug in forum Tech Board
    Replies: 10
    Last Post: 09-05-2005, 03:30 PM
  5. Need a suggestion on a school project..
    By Screwz Luse in forum C Programming
    Replies: 5
    Last Post: 11-27-2001, 02:58 AM