Re: [Dev-C++] FILE positionning problem.
Open Source C & C++ IDE for Windows
Brought to you by:
claplace
|
From: Provic <pr...@wa...> - 2003-07-07 14:35:21
|
>
>
>> Hi !
>> My current problem is a little weird : I read in the man-pages that
>> fgetc increases automatically the position in a current opened file.
>> So my program reads each character of this file in a while : it
>> should do that, but in fact it doesn't.
>> I resolved that by repositionning each time by fseek (param :
>> SEEK_SET) at the right position ; but a file access monitoring daemon
>> showed me that my program isn't optimised at all, it performs 2 fseek
>> which are exactly the sames...
>> Where is the bug ?
>> I verified my code, no need to include it : no pb here.
>>
>
>
>
> I think you had better post your code.
>
So that is my code (no comments, they were in french)
void func()
{
FILE *Fcarte;
long int pos; // Position
char Charou; // The character, converted in char
int ICharou; // The original character
Fcarte=fopen(carte, "r");
if (Fcarte==NULL)
{
printf("Impossible d'ouvrir de fichier bsp.\n");
return;
}
while(1)
{
pos = ftell(Fcarte); //
_________________Nb 1
ICharou=fgetc(Fcarte);
/* if (ICharou==EOF) // Here were there
an EOF test : I removed it, it did bug a lot (?)
break; */
Charou=(char) ICharou;
/*
[stuff, using Charou...] */
fseek(Fcarte, pos+1, SEEK_SET); // _________________Nb 2
}
}
before adding Nb1 and Nb2, it worked too buggly (?). thereafter, it
works too slowly (normal).
Hoping you will help, Thankssssss
Hervé
|