Newbie's problem with fopen

Andre Kirchner sieg1974@yahoo.com
Fri Sep 26 00:57:00 GMT 2003


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



More information about the Gcc-help mailing list