GIDForums  

Go Back   GIDForums > Computer Programming Forums > CPP / C++ Forum
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 01-Jun-2005, 11:44
gaoanyu gaoanyu is offline
New Member
 
Join Date: Jun 2005
Location: Bristol, UK
Posts: 26
gaoanyu is on a distinguished road

fopen fails to create a file pointer


Dear Friends,

I am very glad to have found this forum, you are doing a great job!
I have a question regarding the access mode "at+" of fopen(). Please see the following pseudo codes

CPP / C++ / C Code:
void aClass::aFunction()
{
   int anInt = getValue(); // Assign a value to anInt
   FILE *pf = fopen("aTextFile.txt","at+");
   fprintf(pf,"%d",anInt);
   fclose(pf);
}

aFunction is called many times in my program. However, after a number of calls, an error occurred and the program stopped. It seems to me that fopen() can not open aTextFile, beacuse in the debugging window it showed "pf 0x00000000". Can anyone suggest a reason why it gave me this? I am using Microsoft Visual Studio .NET 2003, thank you very much in advance!

David
Last edited by LuciWiz : 01-Jun-2005 at 23:38. Reason: Please insert your C++ code between [c++] & [/c++] tags
  #2  
Old 01-Jun-2005, 13:20
Dave Sinkula Dave Sinkula is offline
Member
 
Join Date: Apr 2005
Posts: 199
Dave Sinkula will become famous soon enough
Maybe you system can tell you.
CPP / C++ / C Code:
void aClass::aFunction()
{
   int anInt = getValue(); // Assign a value to anInt
   FILE *pf = fopen("aTextFile.txt","at+");
   if ( pf )
   {
      fprintf(pf,"%d",anInt);
      fclose(pf);
   }
   else
   {
      perror("aTextFile.txt");
   }
}
  #3  
Old 01-Jun-2005, 21:33
WaltP's Avatar
WaltP WaltP is offline
Outstanding Member
 
Join Date: Feb 2004
Location: Midwest US
Posts: 3,234
WaltP is a name known to allWaltP is a name known to allWaltP is a name known to allWaltP is a name known to allWaltP is a name known to allWaltP is a name known to all
Quote:
Originally Posted by Dave Sinkula
Maybe you system can tell you.
You may also want to read the sticky about how to post questions. You've left out important information.
__________________

Cow: You're a lawyer too?
Mooseblood (mosquito): Ma'am, I was already a bloodsucking parasite. All I needed was a briefcase!
  #4  
Old 05-Jun-2005, 11:16
gaoanyu gaoanyu is offline
New Member
 
Join Date: Jun 2005
Location: Bristol, UK
Posts: 26
gaoanyu is on a distinguished road
Thank you for the reply Dave, and thanks also LuciWiz for correcting the format. I will make sure to post in the right format next time, WaltP.
Back to the post, the perror() function showed me "Too many open files". However, each time after a file is opened, I used fclose() to close it, so I am not sure why there are"Too many open files". Is there any other restriction? Thanks in advance!

David
 
 

Recent GIDBlogNARMY by crystalattice

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Airport Log program using 3D linked List : problem reading from file batrsau C Programming Language 11 29-Feb-2008 07:44
[Tutorial] Pointers in C (Part II) Stack Overflow C Programming Language 0 27-Apr-2005 17:36
CD burner wont burn!! robertli55 Computer Hardware Forum 1 18-Jun-2004 10:53
Yet another CD burner problem: Lite-On LSC-24082K Erwin Computer Hardware Forum 1 22-May-2004 11:28

Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 01:33.


vBulletin, Copyright © 2000 - 2008, Jelsoft Enterprises Ltd.