Thread: A doubt regarding FILE * pointer

  1. #1
    Registered User
    Join Date
    May 2008
    Posts
    31

    A doubt regarding FILE * pointer

    Hello everyone,

    While learning C File I/O I tried the following code :

    Code:
    #include<stdio.h>
    
    int main()
    {
            FILE *fp;
            fp=fopen("source.txt","rb");
            printf("fp = %p\n",fp++);
            printf("fp = %p\n",fp);
            return 0;
    }
    #gcc prg.c
    #./a.out
    Gives the following output :

    fp = 0x8e2a008
    fp = 0x8e2a09c

    On incrementing fp and printing the values there is a difference of 0X94 or 148. How does the difference come to 148?

    Thank you.

  2. #2
    Registered User
    Join Date
    Jun 2005
    Posts
    6,815
    The size of a FILE type is 148 for gcc and its library on your system.

  3. #3
    Registered User
    Join Date
    May 2008
    Posts
    31
    Thanks for the answer I tried

    Code:
    printf("%d\n",sizeof(FILE));
    and got 148.

  4. #4
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    And it's pretty pointless.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  5. #5
    Registered User
    Join Date
    May 2008
    Posts
    31
    i am still in the process of learning C, so just tried that. I know its pointless.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. File transfer- the file sometimes not full transferred
    By shu_fei86 in forum C# Programming
    Replies: 13
    Last Post: 03-13-2009, 12:44 PM
  2. gcc link external library
    By spank in forum C Programming
    Replies: 6
    Last Post: 08-08-2007, 03:44 PM
  3. Direct3D problem
    By cboard_member in forum Game Programming
    Replies: 10
    Last Post: 04-09-2006, 03:36 AM
  4. Post...
    By maxorator in forum C++ Programming
    Replies: 12
    Last Post: 10-11-2005, 08:39 AM