Re: stream io in c
- From: Ron Ford <ron@xxxxxxxxxxxxxxx>
- Date: Wed, 30 Jul 2008 19:10:07 -0600
On Tue, 29 Jul 2008 19:49:54 -0600, Ron Ford posted:
I think the solution in c could be as easy as instantiating a loop from
zero to 255, putchar'ing in the body of the loop, then redirecting output
to a file. If the creation of the file comes from the source, I suspect it
would have to be in 'rb' mode.
I've tried some variations with this.
int i;
for (i = 0; i <= UCHAR_MAX; i++) putchar (i);
When stdout is redirected to a file, I get a file of size 257 bytes. I
wanted to see if that would also be the case if I created the file from
source, but I've got type mismatches here:
#include <stdio.h>
int main(void)
{
FILE *fp;
char name[]="text58.txt";
fp=&name;
int c;
if ((fp = fopen(fp, "rb")) == NULL)
{
printf("can't open %s\n", fp);
return 1;
}
else
{
for (c = 0; c <= 255; c ++) {
putc(c, fp);
}
fclose(fp);
}
return 0;
}
// gcc -o chars mkchars1.c
This compiles but gcc warns of incompatible pointer types. As of now, it
tells me it can't open. I can't find an example in K&R where they hard-code
a filename like this, so I'm a little stuck.:-(
--
We are here and it is now. Further than that, all human knowledge is
moonshine. 3
H. L. Mencken
.
- Follow-Ups:
- Re: stream io in c
- From: Nick Keighley
- Re: stream io in c
- From: CBFalconer
- Re: stream io in c
- From: Keith Thompson
- Re: stream io in c
- From: Ben Bacarisse
- Re: stream io in c
- From: Richard Heathfield
- Re: stream io in c
- References:
- stream io in c
- From: Ron Ford
- stream io in c
- Prev by Date: Re: [BC] C tutorial q4
- Next by Date: Re: [BC] C tutorial q4
- Previous by thread: Re: stream io in c
- Next by thread: Re: stream io in c
- Index(es):
Relevant Pages
|