Problems with formatting text.
I am making a rather large windows program written in the basic Win32 API with C/C++. I want to have a short paragraph explaing the program and some basic legal stuff on the opening window. In order to do this I went to my trusty old bookcase, pulled out "Programming Windows" by Charles Petzold. He has a program in chapter 17 called "Justify" that I could modify to my own needs. I read the code and his explanation and everything seemed to make sense. I tried to implement(direct copy and paste out of the included e-book) and got 71 errors. I fixed alot of of them by re-typing the ' and the -> symbols for some reason. I am now getting 16 errors which make no sense at all. First a copy of my code
Code:
#include "StdAfx.h"
void Justify (HDC hdc, PTSTR pText, RECT *prc, int iAlign)
{
int xStart, yStart, cSpaceChars ;
PTSTR pBegin, pEnd ;
SIZE size ;
yStart = prc->top ;
do // for each text line
{
cSpaceChars = 0 ; // initialize number of spaces in line
while (*pText == '\0') // skip over leading spaces
pText++ ;
pBegin = pText ; // set pointer to char at beginning of line
do // until the line is known
{
pEnd = pText ; // set pointer to char at end of line
// skip to next space
while (*pText != '\0' && *pText++ != '\0') ;
if (*pText == '\0')
break ;
// after each space encountered, calculate extents
cSpaceChars++ ;
GetTextExtentPoint32(hdc, pBegin, pText - pBegin - 1, &size) ;
}
while (size.cx < (prc->right − prc->left)){
cSpaceChars−− ; // discount last space at end of line
}
while (*(pEnd − 1) == ' ') // eliminate trailing spaces
{
pEnd−− ;
cSpaceChars−− ;
}
// if end of text and no space characters, set pEnd to end
if (*pText == '\0' || cSpaceChars <= 0){
pEnd = pText ;
}
GetTextExtentPoint32 (hdc, pBegin, pEnd − pBegin, &size) ;
switch (iAlign) // use alignment for xStart
{
case IDM_ALIGN_CENTER:
xStart = (prc->right + prc->left − size.cx) / 2 ;
break ;
}
// display the text
TextOut (hdc, xStart, yStart, pBegin, pEnd - pBegin) ;
// prepare for next line
SetTextJustification (hdc, 0, 0) ;
yStart += size.cy ;
pText = pEnd ;
}
while (*pText && yStart < prc->bottom - size.cy) ;
}
Here is a list of errors I am getting
Code:
c:\documents and settings\administrator\my documents\my projects\dosage\justify.cpp(27) : error C2146: syntax error : missing ')' before identifier '−'
c:\documents and settings\administrator\my documents\my projects\dosage\justify.cpp(27) : error C2059: syntax error : ')'
c:\documents and settings\administrator\my documents\my projects\dosage\justify.cpp(27) : error C2143: syntax error : missing ';' before '{'
c:\documents and settings\administrator\my documents\my projects\dosage\justify.cpp(28) : error C2065: 'cSpaceChars−−' : undeclared identifier
c:\documents and settings\administrator\my documents\my projects\dosage\justify.cpp(30) : error C2146: syntax error : missing ')' before identifier '−'
c:\documents and settings\administrator\my documents\my projects\dosage\justify.cpp(30) : error C2059: syntax error : ')'
c:\documents and settings\administrator\my documents\my projects\dosage\justify.cpp(31) : error C2143: syntax error : missing ';' before '{'
c:\documents and settings\administrator\my documents\my projects\dosage\justify.cpp(32) : error C2065: 'pEnd−−' : undeclared identifier
c:\documents and settings\administrator\my documents\my projects\dosage\justify.cpp(39) : error C2146: syntax error : missing ')' before identifier '−'
c:\documents and settings\administrator\my documents\my projects\dosage\justify.cpp(39) : error C2660: 'GetTextExtentPoint32W' : function does not take 3 arguments
c:\documents and settings\administrator\my documents\my projects\dosage\justify.cpp(39) : error C2059: syntax error : ')'
c:\documents and settings\administrator\my documents\my projects\dosage\justify.cpp(43) : error C2146: syntax error : missing ')' before identifier '−'
c:\documents and settings\administrator\my documents\my projects\dosage\justify.cpp(43) : error C2059: syntax error : ')'
All of these errors seem to be caused by the use of - I have tried to re-type them and nothing(side question why does re-typing stuff matter?). Can anyone help? I am using Visual Studio 2005 Professional.
Thank you very much.