new to file handling!

This is a discussion on new to file handling! within the C Programming forums, part of the General Programming Boards category; the following code which just displays file contents compiles successfully but give runtime error!! Code: #include <stdio.h> int main() { ...

  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
    32,847
    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.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  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
    32,847
    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.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  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, 12:43 PM
  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, 04:44 PM
  4. Batch file programming
    By year2038bug in forum Tech Board
    Replies: 10
    Last Post: 09-05-2005, 04: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

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