problem with reading struct from file generated by hexdump

This is a discussion on problem with reading struct from file generated by hexdump within the C Programming forums, part of the General Programming Boards category; Originally Posted by whiteflags I'm not convinced he needs a collection of records at all. The OP doesn't know how ...

  1. #16
    Registered User
    Join Date
    Oct 2008
    Location
    TX
    Posts
    2,047
    Quote Originally Posted by whiteflags View Post
    I'm not convinced he needs a collection of records at all.
    The OP doesn't know how many records are in that file, besides (s)he needs to print them out at the end. Doesn't that say linked list loud 'n clear.

  2. #17
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    21,739
    Quote Originally Posted by itCbitC
    The OP doesn't know how many records are in that file, besides (s)he needs to print them out at the end. Doesn't that say linked list loud 'n clear.
    No, it does not. You certainly can deal with an indefinite number of records and print them all if you process them one at a time. What suggests to me that a container would be useful is the need to sort and perform some unspecified manipulations of the records.
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  3. #18
    Registered User
    Join Date
    Oct 2008
    Location
    TX
    Posts
    2,047
    Quote Originally Posted by laserlight View Post
    No, it does not. You certainly can deal with an indefinite number of records and print them all if you process them one at a time. What suggests to me that a container would be useful is the need to sort and perform some unspecified manipulations of the records.
    No you don't need a linked list if you want to process each record in the input file and print it out at the same time, however if you want to store them for later printing or processing then you do need a linked list as a dynamically allocated array won't do in that case. That's what I was trying to get across.
    Last edited by itCbitC; 12-23-2008 at 12:07 PM.

  4. #19
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    21,739
    Quote Originally Posted by itCbitC
    No you don't need a linked list if you want to process each record in the input file and print it out at the same time, however if you want to store them for later printing or processing then you do need a linked list. That's what I was trying to get across.
    You do not need a linked list, but a linked list certainly would be an option. I would argue that a dynamically allocated array should actually be the "default" to use here, not a linked list. Among other things, sorting would be somewhat easier since qsort() can be used.
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  5. #20
    Registered User whiteflags's Avatar
    Join Date
    Apr 2006
    Location
    United States
    Posts
    7,706
    I just want to point out that I completely understand when 'containers' are useful but that the OPs example was purposefully misleading. All he had to do was include some clue about a sorting step or one of those unspecified operations for me to understand.

    Regardless of how wrong I am it appears the OP understands perfectly what went wrong. I'm surprised I did anything worth a thank you, but... confusion happens.

  6. #21
    Registered User
    Join Date
    Oct 2008
    Location
    TX
    Posts
    2,047
    Quote Originally Posted by laserlight View Post
    You do not need a linked list, but a linked list certainly would be an option. I would argue that a dynamically allocated array should actually be the "default" to use here, not a linked list. Among other things, sorting would be somewhat easier since qsort() can be used.
    So you're implying a malloc() followed by realloc()'s??

  7. #22
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    21,739
    Quote Originally Posted by whiteflags
    I just want to point out that I completely understand when 'containers' are useful but that the OPs example was purposefully misleading. All he had to do was include some clue about a sorting step or one of those unspecified operations for me to understand.
    I'll give wollek the benefit of the doubt and say that it was merely accidentally misleading

    Quote Originally Posted by itCbitC
    So you're implying a malloc() followed by realloc()'s??
    Yes, plus tracking of the size and capacity.
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  8. #23
    Registered User
    Join Date
    Dec 2008
    Posts
    8
    Quote Originally Posted by whiteflags View Post

    Consider that your RAM might not be enough to hold a million records at once.
    Sounds like you are a PC based programmer :-)

    The little testprogram I posted was just for demonstration.
    The screen output is not needed.

    The main program is to work with the data. Things like maxima,minima, std deviation , average over a certain time period, a whole bunch of std. mathematical analytics.
    This is the part I do not have trouble. I just had encountered the problem that my little test program ran fine while when putting it to the test on a datablock it had failed.
    As I said I was chasing the hexdump and had not realized that there was something wrong with my pointer mechanics .
    That's when you think you can rest you programming skills for a decade or two and pick up where you have left. :-)

    So thanks again for your help, you put me on the right track.

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

Similar Threads

  1. Converting from C to C++
    By Taka in forum C++ Programming
    Replies: 5
    Last Post: 04-08-2009, 02:16 AM
  2. Post...
    By maxorator in forum C++ Programming
    Replies: 12
    Last Post: 10-11-2005, 08:39 AM
  3. Binary Search Trees Part III
    By Prelude in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 10-02-2004, 03:00 PM
  4. towers of hanoi problem
    By aik_21 in forum C Programming
    Replies: 1
    Last Post: 10-02-2004, 01:34 PM
  5. Request for comments
    By Prelude in forum A Brief History of Cprogramming.com
    Replies: 15
    Last Post: 01-02-2004, 09:33 AM

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