cvs.gedasymbols.org/archives/browse.cgi   search  
Mail Archives: djgpp/1997/09/02/20:57:39

Date: Tue, 2 Sep 1997 19:54:34 -0500 (CDT)
From: Andrew Deren <aderen AT eecs DOT uic DOT edu>
To: Paul Derbyshire <ao950 AT FreeNet DOT Carleton DOT CA>
cc: djgpp AT delorie DOT com
Subject: Re: Help with strings MID$?
In-Reply-To: <5u8ai8$22o@freenet-news.carleton.ca>
Message-ID: <Pine.SUN.3.95.970902195216.19406A-100000@ernie.eecs.uic.edu>
MIME-Version: 1.0

On 30 Aug 1997, Paul Derbyshire wrote:

> 
> Orlando Andico (orly AT gibson DOT eee DOT upd DOT edu DOT ph) writes:
> > The Joy of Pointers (tm)  :)
> > 
> > char *mystring="1234567890";
> > char *mid3;
> > 
> > to get characters 5..7 (destructively though)
> > mystring[7] = '\0';  /* chop off 8th character and rest */
> > mid3 = mystring + 5; /* point to fifth character */
> > 
> > and you're there!!
> 
> Or, leave mystring[7] alone and use strncpy or strncat with 'n' equal to 3.
> (And you meant mystring + 4 right? mystring + 0 is the first char, + 4 is
> the fifth.)
But where are you going to copy it to?
mid3 is just a pointer pointint somewhere to your memory. if you want
to use strncpy you first have to allocate memory for mid3.


> --
>     .*.  Where feelings are concerned, answers are rarely simple [GeneDeWeese]
>  -()  <  When I go to the theater, I always go straight to the "bag and mix"
>     `*'  bulk candy section...because variety is the spice of life... [me]
> Paul Derbyshire ao950 AT freenet DOT carleton DOT ca, http://chat.carleton.ca/~pderbysh
> 


                        ,,,
                       (0 0)
   +-------------oOO----(_)-------------------+
   |                Andrew Deren              |  
   |             aderen AT eecs DOT uic DOT edu          |
   | www.eecs.uic.edu/~aderen/ader/main.html  |
   +-------------------------oOO--------------+
                       || ||
                      ooO Ooo
 


- Raw text -


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