Mail Archives: djgpp/2002/02/24/14:03:13
"Bill Henderson" <inconnu AT softhome DOT net> wrote in
news:006f01c1bd25$839675c0$088f6518 AT mtww DOT phub DOT net DOT cable DOT rogers DOT com:
> Attachment decoded: untitled-3.htm
> ------=_NextPart_000_006A_01C1BCFB.831E51A0--
please do not post html in newsgroups.
> I downloaded and installed DJGPP without problem.
good.
> But on trying to produce something non-trivial, the lack of string
> handling functions in libc seems to be a limiting function.
huh ?
> (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:
more on this below.
> (2) Is it really necessary to use arrays to satisfactorily manipulate
> strings?
strings in c are character arrays. there is no data type called a string.
> (3) I notice getchar() misbehaving and, although I didn't replicate
> the situation in the code below, I have had to clear the buffer with
> extra, and to my way of thinking, unnecessary, throw_away_int =
> getchar() calls. I had thought getchar() was echoed and buffered, and
> a peak at an old manual confirms this? Am I missing something here?
do look at the stdio section of the C faq list:
http://www.eskimo.com/~scs/C-faq/s12.html
> {START CODE]
> /* test */
>
> #include <stdio.h>
>
> int main()
>
> {
>
> char lf[2] = { '\n' } ;
>
> int i = 0 ;
>
> char ch[8][2] = { "1", "%", "\%", "2", "\\", "3", "\"", "4" } ;
>
> FILE *fp ;
>
> fp = fopen( "file1.lst", "w" ) ;
>
> for ( i = 0 ; i < 8 ; i++ )
>
> {
>
> printf( "\ncharacter %n == %s ", i, ch[i] ) ;
>
> fprintf( fp, ch[i] ) ;
type
info libc alpha fprintf
at the command prompt (or use rhide's info browser to locate the same
information) and look at the syntax of fprintf.
basically, the second argument to fprintf is the format, not the
character you want to print.
obviously, the right solution, if you want to print a single character,
is to use:
fputc('%', fp);
or
fputc(ch[i], fp);
note that these are not djgpp specific. they are basic C questions which
should be posted on comp.lang.c.moderated or comp.lang.c, and you should
definitely check the C faq before posting.
sinan.
- Raw text -