17.02.2015 Views

CCS C Compiler Manual PCB / PCM / PCH

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

searches for a token will return null.<br />

If one is found, it is overwritten by '\0', which terminates current<br />

token. Function saves pointer to following character from which next search<br />

will start.<br />

Each subsequent call, with 0 as first argument, starts searching from the<br />

saved pointer.<br />

Availability:<br />

Requires:<br />

Examples:<br />

All devices.<br />

#INCLUDE <br />

char string[30], term[3], *ptr;<br />

strcpy(string,"one,two,three;");<br />

strcpy(term,",;");<br />

ptr = strtok(string, term);<br />

while(ptr!=0) {<br />

puts(ptr);<br />

ptr = strtok(0, term);<br />

}<br />

// Prints:<br />

one<br />

two<br />

three<br />

Example Files:<br />

Also See:<br />

ex_str.c<br />

strxxxx(), strcpy()<br />

strtol( )<br />

Syntax:<br />

Parameters:<br />

Returns:<br />

Function:<br />

result=strtol(nptr,& endptr, base)<br />

nptr and endptr are strings and base is an integer<br />

result is a signed long int.<br />

returns the converted value in result , if any. If no conversion could be<br />

performed, zero is returned.<br />

The strtol function converts the initial portion of the string pointed to by nptr to<br />

a signed long int representation in some radix determined by the value of<br />

base. The part of the string after conversion is stored in the object pointed to<br />

endptr, provided that endptr is not a null pointer. If nptr is empty or does not<br />

have the expected form, no conversion is performed and the value of nptr is<br />

stored in the object pointed to by endptr, provided endptr is not a null pointer.<br />

322

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!