note 55673 deleted from function.fscanf by vincent
| From: | vincent@php.net | Date: | Wed, 10 Aug 2005 13:26:06 +0000 |
| Subject: | note 55673 deleted from function.fscanf by vincent | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-93372@lists.php.net to get a copy of this message | ||
Note Submitter:
Reason: bad code
----
Here is my code to read a line by line from a file
{
long lFileSize,i;
int iCount = 0;
int iInitialBlockSize=1000;
int p;
FILE *pFilePt;
g_szFileRetrieved = (char **)calloc( iInitialBlockSize, sizeof(char *) );
pFilePt = fopen (szDAT_FileName, "rb");
while( !(pFilePt->state.eof) )
{
g_szFileRetrieved[iCount] = (char *)calloc(500, sizeof(char));
i = fscanf (pFilePt, "%[^\n]\n", g_szFileRetrieved[iCount]);
printf("i = %i", i);
printf("g_szFileRetrieved[%i] --> %s\n", iCount, g_szFileRetrieved[iCount] );
if( i==0||i==-1 )
{
printf("\n\nAn error occurred during file loading !!\n\n");
break;
}
else
iCount++;
if(iCount>=iInitialBlockSize)
{
iInitialBlockSize = iInitialBlockSize + 1000;
g_szFileRetrieved = realloc (g_szFileRetrieved, sizeof(char **)*iInitialBlockSize);
}
}
}