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.

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.

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.

Comments
Show your attempt first. And use code tags.

>how can I fix it to where it reads 16 bytes at a time.
Without looking at the code:

char buffer[17];

...

fgets ( buffer, sizeof buffer, in );

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.

>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.

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.

>but anyway what would be a code that works for an 16 byte buffer.
Be more specific. The following is a 16 byte buffer:

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.

This article has been dead for over six months. Start a new discussion instead.