File pointers as function parameters

This is a discussion on File pointers as function parameters within the C Programming forums, part of the General Programming Boards category; Yeah, cheers mate, that did the trick. Ah, it's amazing, a few weeks ago I thought I knew it all ...

  1. #16
    Registered User
    Join Date
    Jan 2005
    Posts
    20
    Yeah, cheers mate, that did the trick.

    Ah, it's amazing, a few weeks ago I thought I knew it all with C, but these dynamic parameters are a totally new challenge for me, and yet again, it's the simple things with pointers that I mess up on.

    Thanks alot.

  2. #17
    Just Lurking Dave_Sinkula's Avatar
    Join Date
    Oct 2002
    Posts
    5,006
    Code:
    void ReadGroup(FILE **PtrfilePtr)
    {
            char toWrite;
    
            while (toWrite != EOF)
            {
                    toWrite = getc(*PtrfilePtr);
                    printf("%c", toWrite);
            }
    }
    toWrite should be an int: FAQ.
    Last edited by Dave_Sinkula; 01-17-2005 at 03:05 PM.
    7. It is easier to write an incorrect program than understand a correct one.
    40. There are two ways to write error-free programs; only the third one works.*

  3. #18
    UT2004 Addict Kleid-0's Avatar
    Join Date
    Dec 2004
    Posts
    656
    Code:
    void ReadGroup(FILE **PtrfilePtr) {
            int toWrite;
    
            while (toWrite != EOF) {
                    toWrite = getc(*PtrfilePtr);
                    printf("%c", toWrite);
            }
    }
    Some people may ask, why int and not char? Well, *sits down in front of a fire and hands out cookies and milk*, you see...
    char = 1 byte
    int = 4 byte
    -----------
    You see, char's can only hold so many values, 255 to be exact. EOF is not part of the family of 255. You have to remember that char is a number. So we use the ~32000 values of int to be used as error messages, because a char doesn't have enough values, because they're all reserved for real character values.

  4. #19
    & the hat of GPL slaying Thantos's Avatar
    Join Date
    Sep 2001
    Posts
    5,681
    Some people may ask, why int and not char? Well, *sits down in front of a fire and hands out cookies and milk*, you see...
    char = 1 byte
    int = 4 byte
    -----------
    You see, char's can only hold so many values, 255 to be exact. EOF is not part of the family of 255. You have to remember that char is a number. So we use the ~32000 values of int to be used as error messages, because a char doesn't have enough values, because they're all reserved for real character values
    Please shut up now, and remain that way until you learn more.

  5. #20
    UT2004 Addict Kleid-0's Avatar
    Join Date
    Dec 2004
    Posts
    656
    No cookie for you

  6. #21
    Registered User
    Join Date
    Jan 2005
    Posts
    20
    I see, that's a good point. I actually thought that EOF was a special character, but I see it's a macro.

    Thanks again.

  7. #22
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Quote Originally Posted by Kleid-0
    Code:
    void ReadGroup(FILE **PtrfilePtr) {
            int toWrite;
    
            while (toWrite != EOF) {
                    toWrite = getc(*PtrfilePtr);
                    printf("%c", toWrite);
            }
    }
    Some people may ask, why int and not char? Well, *sits down in front of a fire and hands out cookies and milk*, you see...
    char = 1 byte
    int = 4 byte
    -----------
    You see, char's can only hold so many values, 255 to be exact. EOF is not part of the family of 255. You have to remember that char is a number. So we use the ~32000 values of int to be used as error messages, because a char doesn't have enough values, because they're all reserved for real character values.
    Just to point this out, 2^32 is not 32000. It's roughly four billion. You're thinking of two byte integers, or what's usually (x86-ish) known as "16 bit integers". I'd suggest upgrading your compiler while you're busy learning more. And for the record, a char is CHAR_BIT bits in size (excluding potential padding), and has a value range of CHAR_MIN through CHAR_MAX.

    Quzah.
    Hope is the first step on the road to disappointment.

Page 2 of 2 FirstFirst 12
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Undefined Reference Compiling Error
    By AlakaAlaki in forum C++ Programming
    Replies: 1
    Last Post: 06-27-2008, 12:45 PM
  2. Inventory records
    By jsbeckton in forum C Programming
    Replies: 23
    Last Post: 06-28-2007, 05:14 AM
  3. Replies: 3
    Last Post: 03-04-2005, 02:46 PM
  4. Unknown Memory Leak in Init() Function
    By CodeHacker in forum Windows Programming
    Replies: 3
    Last Post: 07-09-2004, 10:54 AM
  5. what does this mean to you?
    By pkananen in forum C++ Programming
    Replies: 8
    Last Post: 02-04-2002, 03:58 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21