| | |
Input Buffer
Please support our C advertiser: Programming Forums - DaniWeb Sister Site
![]() |
•
•
Join Date: Nov 2004
Posts: 45
Reputation:
Solved Threads: 1
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.
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.
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
>how can I fix it to where it reads 16 bytes at a time.
Without looking at the code:
Without looking at the code:
C Syntax (Toggle Plain Text)
char buffer[17]; ... fgets ( buffer, sizeof buffer, in );
New members chased away this month: 3
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.
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.
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
>but anyway what would be a code that works for an 16 byte buffer.
Be more specific. The following is a 16 byte buffer:
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.
Be more specific. The following is a 16 byte buffer:
C Syntax (Toggle Plain Text)
char buffer[16];
New members chased away this month: 3
![]() |
Similar Threads
- Monitoring an input buffer (C++)
- Clearing the input buffer (C++)
- Remove specific number of bytes in the Input buffer (Python)
- Input buffer help transferring between Dos > Unix (C++)
Other Threads in the C Forum
- Previous Thread: MP3 Player
- Next Thread: powers of two, recursion.
| Thread Tools | Search this Thread |
Tag cloud for C
#include ansi array arrays asterisks binarysearch calculate centimeter changingto char convert copyimagefile cprogramme creafecopyofanytypeoffileinc database directory dynamic fflush file fork forloop framework getlasterror givemetehcodez grade graphics gtkgcurlcompiling hacking hardware histogram homework inches include incrementoperators input iso kernel km lazy linked linkedlist linux linuxsegmentationfault list lists locate logical_drives looping loopinsideloop. lowest match matrix microsoft motherboard multi mysql number opendocumentformat opensource owf pattern pdf performance pointer posix problem probleminc process program programming radix recursion recv repetition research reversing scanf scripting segmentationfault sequential shape socket socketprograming spoonfeeding standard string strings structures student systemcall testing threads turboc unix user variable voidmain() wab windows.h windowsapi






