Mail Archives: djgpp/2002/02/24/12:30:46
Thanks for the response Hans-Bernhard. It was much appreciated.
However, the printf( "\ncharacter %n == %s ", i, ch[i] ) ; in the loop was
intended to dump the character to the screen and not put it into a
file.......
But let me rephrase my question very simply:
How do I put a percent (%) character into a file? Given that the attempts as
per my original post do not work.
Thanks in advance
Bill Henderson
----- Original Message -----
From: "Hans-Bernhard Broeker" <broeker AT physik DOT rwth-aachen DOT de>
Newsgroups: comp.os.msdos.djgpp
To: <djgpp AT delorie DOT com>
Sent: Sunday, February 24, 2002 9:42 AM
Subject: Re: String Problems
> Bill Henderson <inconnu AT softhome DOT net> wrote:
>
> > (1) Why will the following code output to the screen perfectly (with
> > the percent symbol output correctly either escaped or not), whilst
> > it is impossible to place the percent character into a file which
> > produces:
>
> It definitely is possible, but you're trying it the wrong way. Note the
difference
> between:
>
> > printf( "\ncharacter %n == %s ", i, ch[i] ) ;
> ^^^ ^^^^^
> and:
>
> > fprintf( fp, ch[i] ) ;
> ^^^^
>
> There's no "%s" format anywhere, in the fprintf() case.
>
> fprintf(fp, "%s\n", ch[i]);
>
> would have been closer to the goal. An alternative would have been
>
> fputs(ch[i], fp); fputc('\n', fp);
>
> or fputc(ch[i][0], fp); fputc('\n', fp);
>
>
> > (2) Is it really necessary to use arrays to satisfactorily
> > manipulate strings?
>
> Yes. Strings *are* arrays in C.
>
> > (3) I notice getchar() misbehaving
> [...]
>
> Sorry, but without explaining what the "misbehaviour" was, it's hard
> to help you here.
>
> --
> Hans-Bernhard Broeker (broeker AT physik DOT rwth-aachen DOT de)
> Even if all the snow were burnt, ashes would remain.
- Raw text -