www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/2002/02/24/14:03:13

X-Authentication-Warning: delorie.com: mailnull set sender to djgpp-bounces using -f
From: "A. Sinan Unur" <asu1 AT cornell DOT edu>
Newsgroups: comp.os.msdos.djgpp
Subject: Re: String Problems
Date: 24 Feb 2002 18:28:57 GMT
Organization: Cornell University
Lines: 90
Sender: asu1 AT cornell DOT invalid (on pool-141-149-207-111.syr.east.verizon.net)
Message-ID: <Xns91BF892525AC9asu1cornelledu@132.236.56.8>
References: <006f01c1bd25$839675c0$088f6518 AT mtww DOT phub DOT net DOT cable DOT rogers DOT com>
NNTP-Posting-Host: pool-141-149-207-111.syr.east.verizon.net
X-Trace: news01.cit.cornell.edu 1014575337 1027 141.149.207.111 (24 Feb 2002 18:28:57 GMT)
X-Complaints-To: usenet AT news01 DOT cit DOT cornell DOT edu
NNTP-Posting-Date: 24 Feb 2002 18:28:57 GMT
User-Agent: Xnews/L5
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp
Reply-To: djgpp AT delorie DOT com

"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 -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019