CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums
Results 1 to 3 of 3

Thread: fopen

  1. #1
    Join Date
    Mar 2011



    Thank you very much for taking time from your busy schedule to help me out. I'm using the following code:

    FILE* file;
    file = fopen("logg.txt", "rb");
    int DemonicRainbowUnicorn = sizeof(file);
    file in the debugger gets a Bad Ptr. No matter what file i try to open, the size of the file is always 4. I've tried googling this quite a bit but non of the articles I found helped. Again thank you very much for the help.


  2. #2
    2kaud's Avatar
    2kaud is offline Super Moderator Power Poster
    Join Date
    Dec 2012

    Re: fopen

    file is a pointer to a type FILE. On a 32 bit system, therefore the size of file will always be 4 as pointers are 32 bits. Are you using c or c++? You haven't posted the headers you are using. If you want to know how many bytes there are in the file use
    #include <stdio.h>
    int main()
    FILE* fp;
    long size;
    	fp = fopen("debug.txt", "rb");
    	if (fp == NULL) {
    		puts("Problem opening file");
    	} else {
    		fseek(fp, 0, SEEK_END);
    		size = ftell(fp);
    		printf("size is %li\n", size);
    	return 0;
    If you are using c++, I strongly suggest you use the c++ stream classes for i/o.
    All advice is offered in good faith only. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain

    C++17 Compiler: Microsoft VS2017 (15.4.0)

  3. #3
    Join Date
    Mar 2011

    Re: fopen

    Thank you very much. I am now reading up on stream classes. I hope you have a great day.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Windows Mobile Development Center

Click Here to Expand Forum to Full Width

This a survey!

On-Demand Webinars (sponsored)