Visual C++ and MFC Programming 2nd Edition

(Martin Jones) #1

Visual C++ and MFC Fundamentals Chapter 10: Characteristics of a Window's Frame


}

After formatting the string, the Buffer argument holds the new string. You can then use it
as you see fit. For example, you can pass it to another function such as displaying it on a
view as follows:

void CExerciseView::OnDraw(CDC* pDC)
{
CExerciseDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);

char FirstName[] = "Ferdinand";
char LastName[] = "Coly";
char FullName[40];

sprintf(FullName, "Full Name: %s %s", FirstName, LastName);
int Len = strlen(FullName);

pDC->TextOut(20, 20, FullName, Len);
}

9.2 Operations of Strings...................................................................................


9.2.1 String Copy...........................................................................................


Copying a string is equivalent to assigning all of its characters to another string. After
copying, both strings would have the same value. To copy a null-terminated string, you
can use the strcpy() function. Its syntax is:

char *strcpy(char *strDestination, const char *strSource);

The strDestination argument is the target string. The strSource argument holds the value
of the string that needs to be copied. During execution, the strSource value would be
assigned to the strDestination variable. After execution, this function returns another
string that has the same value as strDestination.

Here is an example:

void CExerciseView::OnDraw(CDC* pDC)
{
CExerciseDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);

char Artist[] = _T("Arsene Wendt");
char Producer[40];
Free download pdf