This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
Newbie's problem with fopen
- From: Andre Kirchner <sieg1974 at yahoo dot com>
- To: gcc-help at gcc dot gnu dot org
- Date: Thu, 25 Sep 2003 17:57:21 -0700 (PDT)
- Subject: Newbie's problem with fopen
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