12.12.2012 Views

Teach Yourself Borland C++ in 14 Days - portal

Teach Yourself Borland C++ in 14 Days - portal

Teach Yourself Borland C++ in 14 Days - portal

SHOW MORE
SHOW LESS

Create successful ePaper yourself

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

NOTE<br />

Function Description<br />

Gett<strong>in</strong>g Your Feet Wet<br />

strlen() Returns the length of the str<strong>in</strong>g.<br />

strupr() Converts all characters <strong>in</strong> a str<strong>in</strong>g to uppercase.<br />

spr<strong>in</strong>tf() Builds a str<strong>in</strong>g based on a variable number of parameters.<br />

The str<strong>in</strong>g operations discussed here are how str<strong>in</strong>gs are handled <strong>in</strong> C.<br />

Most <strong>C++</strong> compilers provide a cstr<strong>in</strong>g class that simplifies the difficulties<br />

<strong>in</strong>herent <strong>in</strong> the C way of handl<strong>in</strong>g str<strong>in</strong>gs. (<strong>C++</strong>Builder’s Visual<br />

Component Library conta<strong>in</strong>s a class called Str<strong>in</strong>gs that handles str<strong>in</strong>g<br />

operations. Check the <strong>C++</strong>Builder onl<strong>in</strong>e help for more <strong>in</strong>formation on<br />

Str<strong>in</strong>gs.) Although the C way of handl<strong>in</strong>g str<strong>in</strong>gs is a little quirky, it is<br />

by no means obsolete. <strong>C++</strong> programmers use C-style str<strong>in</strong>g operations<br />

on a daily basis as well as str<strong>in</strong>g classes such as cstr<strong>in</strong>g.<br />

I won’t go <strong>in</strong>to examples of all of the str<strong>in</strong>g-manipulation functions listed <strong>in</strong> the table, but<br />

I’ll touch on a couple of the more widely used ones. The strcpy() function is used to copy<br />

one str<strong>in</strong>g to another. The source str<strong>in</strong>g can be a variable or a str<strong>in</strong>g literal. Take the follow<strong>in</strong>g<br />

code, for example:<br />

// set up a str<strong>in</strong>g to hold 29 characters<br />

char buff[30];<br />

// copy a str<strong>in</strong>g literal to the buffer<br />

strcpy(buff, “This is a test.”);<br />

// display it<br />

cout

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

Saved successfully!

Ooh no, something went wrong!