944,141 Members | Top Members by Rank

Ad:
  • C Discussion Thread
  • Unsolved
  • Views: 4208
  • C RSS
Nov 4th, 2004
0

Input Buffer

Expand Post »
Hello, I am in a C+ programming class at my college where I am at, and for one fo my labs I have to create a program similar to hexdump of linux, I can do everything it asks me to do, but I can't figure out how to do the input buffer, can somebody send me a code that would make the program read a file 16 bytes at a time. And oculd you please send it to edited by moderator Thanks in advance.
Last edited by alc6379; Nov 4th, 2004 at 11:59 pm.
Similar Threads
Reputation Points: 10
Solved Threads: 1
Light Poster
jifiii is offline Offline
45 posts
since Nov 2004
Nov 4th, 2004
0

Re: Input Buffer

We don't write your code for you-- we're here to help you learn.

Please at least attempt to write something, and meanwhile, we might be able to give you some pointers. Also, posting your email address for us to send you the output is also counterproductive to the goal of this forum; we want to make our knowledge available to all, not just you.
Team Colleague
Reputation Points: 186
Solved Threads: 147
Cookie... That's it
alc6379 is offline Offline
2,519 posts
since Dec 2003
Nov 5th, 2004
-1

Re: Input Buffer

That is the thing I can't figure out how to do the buffer, that is why I am asking somebody to show me how to do it.
Reputation Points: 10
Solved Threads: 1
Light Poster
jifiii is offline Offline
45 posts
since Nov 2004
Nov 5th, 2004
0

Re: Input Buffer

Oh here is the code I have so far, how can I fix it to where it reads 16 bytes at a time.
Attached Files
File Type: c getBuffer.c (612 Bytes, 102 views)
Reputation Points: 10
Solved Threads: 1
Light Poster
jifiii is offline Offline
45 posts
since Nov 2004
Nov 5th, 2004
0

Re: Input Buffer

>how can I fix it to where it reads 16 bytes at a time.
Without looking at the code:
  1. char buffer[17];
  2.  
  3. ...
  4.  
  5. fgets ( buffer, sizeof buffer, in );
Administrator
Reputation Points: 6442
Solved Threads: 1393
Bad Cop
Narue is offline Offline
11,807 posts
since Sep 2004
Nov 5th, 2004
0

Re: Input Buffer

How exactly is that suppose to fix anything?
Reputation Points: 10
Solved Threads: 1
Light Poster
jifiii is offline Offline
45 posts
since Nov 2004
Nov 5th, 2004
0

Re: Input Buffer

Your code tries to read 16 chars from the console, but you say you need to be reading from a file. As Naru points out, you can use fgets, or you can use fgetc() or something similar.

int count = 0;
int c;
while ((count < 16 && ((c = fgetc(f)) != EOF))
{
// increment count, save c in an array
}
// here count may be 16, or it may be less if you hit EOF.
Reputation Points: 36
Solved Threads: 11
Posting Pro in Training
Chainsaw is offline Offline
436 posts
since Jun 2004
Nov 5th, 2004
0

Re: Input Buffer

>How exactly is that suppose to fix anything?
It reads 16 bytes at a time using a buffer, moron. That's what you asked for. I would give a more detailed answer, but I refuse to download attachments like almost every other experienced board member. If you want detailed help then give a detailed problem. And I'll add that the tone of your posts is annoying. Consider your next post carefully if you want any real help from me, as I can be easily insulted.
Administrator
Reputation Points: 6442
Solved Threads: 1393
Bad Cop
Narue is offline Offline
11,807 posts
since Sep 2004
Nov 5th, 2004
0

Re: Input Buffer

ok, sorry I didn't mean to insult, I didn't think that was insulting, but anyway what would be a code that works for an 16 byte buffer.
Reputation Points: 10
Solved Threads: 1
Light Poster
jifiii is offline Offline
45 posts
since Nov 2004
Nov 5th, 2004
0

Re: Input Buffer

>but anyway what would be a code that works for an 16 byte buffer.
Be more specific. The following is a 16 byte buffer:
  1. char buffer[16];
My code added one to the size for a trailing null character added by fgets. Clearly you aren't communicating your problem adequately or my suggestion would have been a reasonable solution.
Administrator
Reputation Points: 6442
Solved Threads: 1393
Bad Cop
Narue is offline Offline
11,807 posts
since Sep 2004

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C Forum Timeline: MP3 Player
Next Thread in C Forum Timeline: powers of two, recursion.





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC