| |

VerySource

 Forgot password?
 Register
Search
View: 21|Reply: 1

fseek in doubt

[Copy link]

1

Threads

1

Posts

2

Credits

Newbie

Rank: 1

Credits
2

 China

Post time: 2020-3-24 03:30:01
| Show all posts |Read mode
How to back up the file pointer
#include <stdio.h>
main ()
{
    FILE * p = fopen ("c:\\1.txt", "r");
    char cTemp;

    printf ("% ld\n", ftell (p));

    cTemp = fgetc (p);
    printf ("% ld\t", ftell (p));
    printf ("% c\n", cTemp);

    cTemp = fgetc (p);
    printf ("% ld\t", ftell (p));
    printf ("% c\n", cTemp);

    fseek (p, SEEK_CUR, -1L);
     printf ("% ld\n", ftell (p));

    while ((cTemp = fgetc (p))! = EOF)
    {
        printf ("% ld\t", ftell (p));
        printf ("% c\n", cTemp);
    }
    getch ();
}
Reply

Use magic Report

0

Threads

3

Posts

3

Credits

Newbie

Rank: 1

Credits
3

 China

Post time: 2020-7-4 18:30:01
| Show all posts
fseek(p, displacement, starting point); you reversed the parameter
Reply

Use magic Report

You have to log in before you can reply Login | Register

Points Rules

Contact us|Archive|Mobile|CopyRight © 2008-2020|verysource.com ( 京ICP备17048824号-1 )

Quick Reply To Top Return to the list