NULL Problem

This is a discussion on NULL Problem within the C++ Programming forums, part of the General Programming Boards category; I am writing a file encryption program for my senior project (don't worry we are encouraged to seek outside help). ...

  1. #1
    Registered User
    Join Date
    Jun 2004
    Posts
    14

    NULL Problem

    I am writing a file encryption program for my senior project (don't worry we are encouraged to seek outside help). but i am having a problem that many files (such as .doc and .exe) use multiple null characters in their encoding. I need a way to tell the difference between a null and eof. any ideas?

    ~Craw

  2. #2
    & the hat of GPL slaying Thantos's Avatar
    Join Date
    Sep 2001
    Posts
    5,681
    Make sure the variable you are reading into (if done character by character) is of type int and not type char and you shouldn't have any problems.

    Also open the file as a binary file.

  3. #3
    Registered User
    Join Date
    Jun 2004
    Posts
    14

    ???

    I feel a little silly... but how do i input the file as binary as opposed to ascii???

  4. #4
    & the hat of GPL slaying Thantos's Avatar
    Join Date
    Sep 2001
    Posts
    5,681
    Code:
    fopen("somefile", "rb")
    Of course you can use other modes also, the b just means to open it in binary mode.

  5. #5
    Registered User
    Join Date
    Oct 2001
    Posts
    2,934
    >I feel a little silly... but how do i input the file as binary as opposed to ascii???
    Code:
    char buffer[BUFSIZ];
    
    ifstream in(filename,ios::binary);
    in.read(buffer,BUFSIZ);
    Or you could use get() if you prefer reading it one char at a time.

  6. #6
    Registered User
    Join Date
    Jun 2004
    Posts
    14
    I appreciate both of your help, i got it going.

    ~Craw

  7. #7
    Hardware Engineer
    Join Date
    Sep 2001
    Posts
    1,398
    There is some very good information in the Programing FAQ about using EOF.

    EOF is NOT a null character at the end of the file like the null termination at the end of a C-style string. That's the way I misunderstood it until Hammer straightened me out! I thought that EOF only worked for ASCII files... WRONG!!!

    The operating system knows where the end of the file is, and tells your program if EOF is true or false.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Linked List Not Saving Value as Int
    By bar338 in forum C Programming
    Replies: 4
    Last Post: 05-04-2009, 08:53 PM
  2. Why am I getting these errors??
    By maxthecat in forum Windows Programming
    Replies: 3
    Last Post: 02-03-2006, 01:00 PM
  3. Help with yacc/compiler design/seg fault
    By trippeer in forum C Programming
    Replies: 1
    Last Post: 04-08-2005, 04:43 AM
  4. Request for comments
    By Prelude in forum A Brief History of Cprogramming.com
    Replies: 15
    Last Post: 01-02-2004, 10:33 AM
  5. BST/Red and Black Tree
    By ghettoman in forum C++ Programming
    Replies: 0
    Last Post: 10-24-2001, 11:45 PM

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