Input Buffer

Please support our C advertiser: Programming Forums - DaniWeb Sister Site
Reply

Join Date: Nov 2004
Posts: 45
Reputation: jifiii is an unknown quantity at this point 
Solved Threads: 1
jifiii jifiii is offline Offline
Light Poster

Input Buffer

 
0
  #1
Nov 4th, 2004
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.
Reply With Quote Quick reply to this message  
Join Date: Dec 2003
Posts: 2,414
Reputation: alc6379 has a spectacular aura about alc6379 has a spectacular aura about alc6379 has a spectacular aura about 
Solved Threads: 123
Team Colleague
alc6379's Avatar
alc6379 alc6379 is offline Offline
Cookie... That's it

Re: Input Buffer

 
0
  #2
Nov 4th, 2004
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.
Alex Cavnar, aka alc6379
Reply With Quote Quick reply to this message  
Join Date: Nov 2004
Posts: 45
Reputation: jifiii is an unknown quantity at this point 
Solved Threads: 1
jifiii jifiii is offline Offline
Light Poster

Re: Input Buffer

 
-1
  #3
Nov 5th, 2004
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.
Reply With Quote Quick reply to this message  
Join Date: Nov 2004
Posts: 45
Reputation: jifiii is an unknown quantity at this point 
Solved Threads: 1
jifiii jifiii is offline Offline
Light Poster

Re: Input Buffer

 
0
  #4
Nov 5th, 2004
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, 10 views)
Reply With Quote Quick reply to this message  
Join Date: Sep 2004
Posts: 7,823
Reputation: Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute 
Solved Threads: 748
Team Colleague
Narue's Avatar
Narue Narue is online now Online
Senior Bitch

Re: Input Buffer

 
0
  #5
Nov 5th, 2004
>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 );
New members chased away this month: 3
Reply With Quote Quick reply to this message  
Join Date: Nov 2004
Posts: 45
Reputation: jifiii is an unknown quantity at this point 
Solved Threads: 1
jifiii jifiii is offline Offline
Light Poster

Re: Input Buffer

 
0
  #6
Nov 5th, 2004
How exactly is that suppose to fix anything?
Reply With Quote Quick reply to this message  
Join Date: Jun 2004
Posts: 436
Reputation: Chainsaw is an unknown quantity at this point 
Solved Threads: 11
Chainsaw's Avatar
Chainsaw Chainsaw is offline Offline
Unprevaricator

Re: Input Buffer

 
0
  #7
Nov 5th, 2004
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.
Reply With Quote Quick reply to this message  
Join Date: Sep 2004
Posts: 7,823
Reputation: Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute 
Solved Threads: 748
Team Colleague
Narue's Avatar
Narue Narue is online now Online
Senior Bitch

Re: Input Buffer

 
0
  #8
Nov 5th, 2004
>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.
New members chased away this month: 3
Reply With Quote Quick reply to this message  
Join Date: Nov 2004
Posts: 45
Reputation: jifiii is an unknown quantity at this point 
Solved Threads: 1
jifiii jifiii is offline Offline
Light Poster

Re: Input Buffer

 
0
  #9
Nov 5th, 2004
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.
Reply With Quote Quick reply to this message  
Join Date: Sep 2004
Posts: 7,823
Reputation: Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute 
Solved Threads: 748
Team Colleague
Narue's Avatar
Narue Narue is online now Online
Senior Bitch

Re: Input Buffer

 
0
  #10
Nov 5th, 2004
>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.
New members chased away this month: 3
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



Tag cloud for C
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC