From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 10050 invoked by alias); 26 Sep 2003 00:57:23 -0000 Mailing-List: contact gcc-help-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Archive: List-Post: List-Help: Sender: gcc-help-owner@gcc.gnu.org Received: (qmail 10041 invoked from network); 26 Sep 2003 00:57:22 -0000 Received: from unknown (HELO web41412.mail.yahoo.com) (66.218.93.78) by sources.redhat.com with SMTP; 26 Sep 2003 00:57:22 -0000 Message-ID: <20030926005721.65692.qmail@web41412.mail.yahoo.com> Received: from [154.5.113.64] by web41412.mail.yahoo.com via HTTP; Thu, 25 Sep 2003 17:57:21 PDT Date: Fri, 26 Sep 2003 00:57:00 -0000 From: Andre Kirchner Subject: Newbie's problem with fopen To: gcc-help@gcc.gnu.org MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-SW-Source: 2003-09/txt/msg00286.txt.bz2 Hi, I made this function which should to log theLinks into theLogFile, and return -1 if there was a problem, 0 if theLinks has just been logged, or 1 if it was logged before. The problem is that somehow sometimes it cannot open theFile even though theLogFile exits at the market line. Does anyone have any idea about the problem? I'm using gcc on a Linux box if it matters. Thanks a lot, Andre # include "logf.h" int logLink( const char * theLink, const char * theLogFile ) { char theLine[ 256 ]; FILE * theFile; bzero( theLine, 256 ); theFile = fopen( theLogFile, "r+" ); if( theFile == NULL ) { theFile = fopen( theLogFile, "w" ); if( theFile == NULL ) It exits here-> return( -1 ); } while( fgets( theLine, 256, theFile ) ) { if( strcmp( theLine, theLink ) == 0 ) { fclose( theFile ); return( 1 ); } } if( fprintf( theFile, "%s", theLink ) < 0 ) { fclose( theFile ); return( -1 ); } fclose( theFile ); return( 0 ); } __________________________________ Do you Yahoo!? The New Yahoo! Shopping - with improved product search http://shopping.yahoo.com