left( source, count ) in C

Abdenacer Moussaoui nacer at hpmcaa.mcm.hp.com
Sat Mar 17 03:55:54 AEST 1990


How do you write a function that returns the left part of a string in C?

The interface is  left(  source, count ) here are some test cases:

	left( "123456789", 3 ) returns "123"
	left( "123456789", 20 ) returns "123456789"

if    stimef( current_time ) returns "13:45:23:48"
then  left( stimef( current_time ), 8 ) returns "13:45:23"

As you can see in the last case, I would't want left(,) to modify the source
(ie. implementing left something like source[count] = '\0' )

If this definition of left() does not fit "standard" C assumptions
about strings, what how would you code left if source was restricted
to type SMALL_STRINGS defined as typedef char SMALL_STRINGS[500] instead
of just the (char *)?  

Thanks for any info.


Thank you.
--Abdenacer 	(nacer at hpmcaa.mcm.hp.COM)



More information about the Comp.lang.c mailing list