RE: [Dev-C++] FILE positionning problem.
Open Source C & C++ IDE for Windows
Brought to you by:
claplace
|
From: Ioannis V. <iv...@em...> - 2003-07-07 15:56:54
|
> -----Original Message-----
> From: dev...@li...
> [mailto:dev...@li...] On Behalf Of Provic
> Sent: Monday, July 07, 2003 5:31 PM
> To: dev...@li...
> Subject: Re: [Dev-C++] FILE positionning problem.
>
> void func()
I assume you play in C, so make th above void func(void)
void func() and void func(void) are not the same thing in C. In C empty
parenthesis means to not make any argument checking.
For example if you do func(7); and func(NULL); you will get no error
messages.
> {
> FILE *Fcarte;
> long int pos; // Position
> char Charou; // The character, converted in char
> int ICharou; // The original character
>
> Fcarte=fopen(carte, "r");
What is carte. It should be "carte".
> if (Fcarte==NULL)
> {
> printf("Impossible d'ouvrir de fichier bsp.\n");
> return;
> }
>
> while(1)
> {
> pos = ftell(Fcarte);
Useless.
//
> _________________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;
There is no need for casting here.
> /*
> [stuff, using Charou...] */
>
> fseek(Fcarte, pos+1, SEEK_SET);
Useless (in theory, but you said you had problems?).
> _________________Nb 2
> }
>
> }
>
> before adding Nb1 and Nb2, it worked too buggly (?). thereafter, it
> works too slowly (normal).
>
> Hoping you will help, Thankssssss
Assuming you have the file named "carte" (without any extension) run the
following code:
#include <stdio.h>
#include <stdlib.h>
int main(void)
{
FILE *Fcarte=fopen("carte" ,"r");
char c;
int input;
if(Fcarte==NULL)
{
fprintf(stderr, "\nMen the lifeboats. Women and children
first!\n\n");
return EXIT_FAILURE;
}
while((input=fgetc(Fcarte))!=EOF)
{
c=input;
/* Do whatever you want with c */
printf("File pos: %ld\n", ftell(Fcarte));
}
printf("\n\nIn theory the file pointer was advancing 1 long at a time\n");
return 0;
}
The results in my system:
C:\c>copy con carte
I have a mission to my life
^Z
1 file(s) copied.
C:\c>temp
File pos: 1
File pos: 2
File pos: 3
File pos: 4
File pos: 5
File pos: 6
File pos: 7
File pos: 8
File pos: 9
File pos: 10
File pos: 11
File pos: 12
File pos: 13
File pos: 14
File pos: 15
File pos: 16
File pos: 17
File pos: 18
File pos: 19
File pos: 20
File pos: 21
File pos: 22
File pos: 23
File pos: 24
File pos: 25
File pos: 26
File pos: 27
File pos: 29
In theory the file pointer was advancing 1 long at a time
C:\c>
Ioannis Vranos
* Programming pages: http://www.noicys.freeurl.com
* Alternative URL 1: http://run.to/noicys
* Alternative URL 2: http://www.noicys.cjb.net
|