Newsgroups: comp.lang.c
Path: utzoo!henry
From: henry@utzoo.uucp (Henry Spencer)
Subject: Re: left( source, count ) in C
Message-ID: <1990Mar18.005434.12769@utzoo.uucp>
Organization: U of Toronto Zoology
References: <510007@hpmcaa.mcm.hp.com>
Date: Sun, 18 Mar 90 00:54:34 GMT

In article <510007@hpmcaa.mcm.hp.com> nacer@hpmcaa.mcm.hp.com (Abdenacer Moussaoui) writes:
>How do you write a function that returns the left part of a string in C?

From context, it sounds like you don't want to allocate new storage, just
treat the left part of the old string as if it were a string.  And you
specify that the old string not be modified.  Sorry, you can't do this
in C.  A C string is a sequence of characters terminated by a NUL ('\0').
To make the left part into a string, you have to get that NUL in there
somehow, either by modifying the old string or by allocating new
storage (e.g. with malloc()) and building a copy there.
-- 
MSDOS, abbrev:  Maybe SomeDay |     Henry Spencer at U of Toronto Zoology
an Operating System.          | uunet!attcan!utzoo!henry henry@zoo.toronto.edu
