delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1999/04/27/11:00:31

Message-ID: <3725CBFE.AA56CB8F@softhome.net>
From: Chris Mears <chris_mears AT softhome DOT net>
X-Mailer: Mozilla 4.04 [en] (Win95; I)
MIME-Version: 1.0
Newsgroups: comp.os.msdos.djgpp
Subject: Re: I need help adressing characters in a string
References: <Pine DOT SUN DOT 3 DOT 91 DOT 990427152054 DOT 9991B-100000 AT is>
Lines: 40
Date: Wed, 28 Apr 1999 00:38:54 +1000
NNTP-Posting-Host: 139.134.192.84
X-Trace: newsfeeds.bigpond.com 925223658 139.134.192.84 (Wed, 28 Apr 1999 00:34:18 EST)
NNTP-Posting-Date: Wed, 28 Apr 1999 00:34:18 EST
Organization: Telstra BigPond Internet Services (http://www.bigpond.com)
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp
Reply-To: djgpp AT delorie DOT com

Eli Zaretskii wrote:
> 
> On Tue, 27 Apr 1999 fiammy AT my-dejanews DOT com wrote:
> 
> > char *string;
> >
> > void main (void)
> > {
> >  int i;
> >  for (i=; i=lengthof(string); i++)
> >   {
> >   dosomething with string[i];
> >   }
> 
> This is okay, except for some minor problems:
> 
>   char string[100];
>   int main (void)
>   {
>     int i;
>     for (i = 0; i < sizeof (string) - 1; i++)
>       {
>          do_something_with (string[i]);
>       }
>   }
> 

In the for loop:  i < sizeof (string)?  Do you mean strlen() or
something else?  If I recall correctly, sizeof returns the number of
bytes in a data type.  So if string, in this case, is a constant pointer
to char, wouldn't it be 2 or 4 bytes, not the dynamic length of the
string?

Chris


> > I can't do that, the compiler gives me an error.
> 
> What error message(s) did you see, what source (exactly) did you try to
> compile, and what command line did you use to compile it?

- Raw text -


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