Re: C or C++ streams question
- From: Michal Nazarewicz <mina86@xxxxxxx>
- Date: Tue, 26 Sep 2006 17:47:47 +0200
"Bill Cunningham" <nospam@xxxxxxxxx> writes:
I have an x86 boot sector that I can easily use cat boot.s >dev/fd0 or
cdrom to write a master boot record. Now how would one write a small program
in C/C++ to take 512B or 4096 bits to be more exact and write a string of
ascii characters of 1 and 0 using fgetc fputc ? I am guessing string.h would
be needed and of course fstream in C++. Though C++ is soo much simpler than
C C is well know for its low level abilities.
#v+
#include <stdio.h>
int main(void) {
int i = 0, c;
do {
c = fgetc(stdin);
} while (++i<512 && c!=EOF);
fputc('1', stdout);
fputc('0', stdout);
return 0;
}
#v-
Takes 512 bytes of data (unless there was an EOF) and prits string of
scii characters 1 and 0 (a character '1' followed by character '0').
So now, can you say what you really want so that everyone will
understand?
--
Best regards, _ _
.o. | Liege of Serenly Enlightened Majesty of o' \,=./ `o
..o | Computer Science, Michal "mina86" Nazarewicz (o o)
ooo +--<mina86*tlen.pl>--<jid:mina86*jabber.org>--ooO--(_)--Ooo--
.
- References:
- C or C++ streams question
- From: Bill Cunningham
- C or C++ streams question
- Prev by Date: Re: the lowest number of comparisons in string matching
- Next by Date: Re: "It doesn't matter if you're a good programmer, it's the syntax that matters"
- Previous by thread: C or C++ streams question
- Next by thread: Re: C or C++ streams question
- Index(es):
Relevant Pages
|