left( source, count ) in C
Henry Spencer
henry at utzoo.uucp
Sun Mar 18 10:54:34 AEST 1990
In article <510007 at hpmcaa.mcm.hp.com> nacer at 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 at zoo.toronto.edu
More information about the Comp.lang.c
mailing list