TIP: Click on subject to list as thread! ANSI
echo: c_echo
to: Bo Simonsen
from: Pascal Schmidt
date: 2004-01-27 19:34:12
subject: Re: [C] Question about external variable initialization

Hi Bo! :-)

 BS> char* strdup(char* text)
 BS> {
 BS>         char* tmptext = NULL;

 BS>         if(text) /* if text is not NULL */
 BS>         {
 BS>                 tmptext = malloc(strlen(text)+1); 
 BS>                 /* allokate the lenght of text and 1 extra char for 
 BS> the 
 BS>                    string NULL termination */
 BS>                 strcpy(tmptext, text);
 BS>         }

 BS>         return tmptext;
 BS> }
Keep care that your strings are always 0-terminated, otherwise this
will run off the end of the string in strlen().

Ciao
Pascal

--- Msged/LNX 6.1.1
* Origin: By order of the king, the city must empty. (1:153/401.2)
SEEN-BY: 633/267 270
@PATH: 153/401 307 140/1 106/2000 633/267

SOURCE: echomail via fidonet.ozzmosis.com

Email questions or comments to sysop@ipingthereforeiam.com
All parts of this website painstakingly hand-crafted in the U.S.A.!
IPTIA BBS/MUD/Terminal/Game Server List, © 2025 IPTIA Consulting™.