Confusion inputing custom size variables?

This is a discussion on Confusion inputing custom size variables? within the C++ Programming forums, part of the General Programming Boards category; I have been playing with defining custom size data types in structures, like 2 or 4 bit and stuff. But ...

  1. #1
    Registered User
    Join Date
    Mar 2003
    Posts
    30

    Question Confusion inputing custom size variables?

    I have been playing with defining custom size data types in structures, like 2 or 4 bit and stuff.

    But ignoring structures i have enev been having trouble getting data read from a file into standard variables and display as that type of variable correctly. If i input 8 bit i am going to get some sort of char(or cr form feed, not good example, even null i guess). But even inputing in a standard int and using sizeof() or not when i try to travers the whole file and read the bits as a bunch of ints i cannot seem to gather all the bits. I understand using char whould screw things up but an int WILL be a number regardless of the bits.

    Should I be using ifstream.get() or ifstream.read(). Niether seem to work right. Is there something i need to do to contron the file pointer? I was under the assumption that unless specified the default is the file pointer stays at the end of the last bit read.

    If someone could give me an example or reason i connot seem to capture the correct amout of bits before the end of the file i would be gratefull. Among other things i would like to write a hex editor for fun some day. =)

    _____________________________________
    "If we didn't have computer hackers, ESPECIALLY the criminal type, there would be no incentive for the greedy corporate monsters to do any real work."

  2. #2
    Registered User
    Join Date
    Apr 2003
    Posts
    23
    Are you saying that you write a struct to a file and fail to read it back? It could be due to the padding that the compiler normally added to your struct during compilation for optimisation purpose.

    What is the struct define that you are having problem? It'll be helpful if you can show the "faulty" struct that you've been talking about.
    Merc

  3. #3
    Registered User
    Join Date
    Mar 2003
    Posts
    30
    Dont even bother worrying about structures. I cant even get a regular variable to input correctly until the end of the file. And what i am doing is trying to read from any file (not made by a c program) in binary and input the correct amount of bits into various variable types. The problem is no matter what method i use i get maybe 20 - 30 bits and then it hits end of file. Same no matter what file i try.

  4. #4
    Registered User
    Join Date
    Apr 2003
    Posts
    23
    How did you check for End Of File? Snippets please?

  5. #5
    Registered User
    Join Date
    Mar 2003
    Posts
    30

    Angry

    You people make this more complicated then it is. ifstream.eof() of course. So like while (!ifstream.eof()){ifstream.get(buffer, sizeof(buffer))}; ect.
    "...son, what is this COUT << on my birthday card mean?"
    expected ";" line 12, 54, 63, 73....

  6. #6
    Registered User
    Join Date
    Mar 2003
    Posts
    30
    First of all i figured out how to open the file correctly in binary and do the bit operations. My main focus is on the EOF problem. I have read that part of the faq before and it is refering to C not C++. Now the C++ book i have uses a while(!input_file.eof()) as a quite standard way of traversing a file. Now is there any reason I could get a false eof regardless of how I do the check for it. Does text mode input perhaps check for some kind of form-feed or sumthing as eof and then opening without binary causes an early exit of the read?
    "...son, what is this COUT << on my birthday card mean?"
    expected ";" line 12, 54, 63, 73....

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Custom Allocation
    By SevenThunders in forum C Programming
    Replies: 17
    Last Post: 04-09-2007, 04:10 PM
  2. Obtaining the system font in custom size
    By @nthony in forum Windows Programming
    Replies: 6
    Last Post: 08-01-2006, 12:05 AM
  3. An exercise in optimization
    By Prelude in forum Contests Board
    Replies: 10
    Last Post: 04-29-2005, 03:06 PM
  4. Replies: 0
    Last Post: 04-20-2003, 11:24 PM
  5. File Size and File Size on Disk
    By DavidP in forum A Brief History of Cprogramming.com
    Replies: 4
    Last Post: 12-15-2001, 07:03 PM

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