progam can input, store, process and output (individual) characters.

char constants denoted by single char within pair of single quotes:

'a'		//lowercase letters
'W'		//uppercase letters
'$'		//punctuation characters
'9'		//digit characters  '8' is not 8
' '		//blank (or space) character
'\n'		//newline escape sequence
'\t'		//tab
'\\'		//backslash
'ab' is a syntax error, or should be...It won't work.
"ab" is a string
  'a'  is different than "a"
char	             	string

char c1, c2;	//char variables
cin >> c1;	//single char input.  spaces and newlines skipped over
c2 = c1;	//assign char 
cout << c2:	//output the char
char c;
cin >> c;
if (c == 'y')
  cout << "It's a y";

char has integer value as specified in ASCII table:
chars are really small (1 byte) integers
'a' == 97
'b' == 98
'A' == 65
etc. but the actual values are not of much concern to us: never use the numbers.
lowercase letters are continuous ('a'==97,'b'==98,...,'z'==122)
uppercase letters are continuous ('A'==65,...,'Z'==90)
digits are continuous ('0'==48, '1'==49,...,'9'==57)
allows for "natural" sorting using the underlying integers.


char again;
cin >> again;
if (again == 'y')
  //do some stuff
toupper, tolower, isupper, islower etc. functions are in ANSI C++ cctype header file, so include it.
cin >> again;
//variable again is not changed by the toupper function
//returns the uppercase version of the value of again
if (toupper(again) == 'Y')    //allow either y or Y
  //do the same stuff

char low, up;
cin >> low;
up = toupper(low);       //up is uppercase version of low

cin >> low;
if (islower(low))
  up = toupper(low);
  cout << "Input is not a lowercase letter";

char c;
cin >> c;
while (islower(c)) {
  cout << "Error.  Must be non lowercase letter. "
       << "Reenter: ";
  cin >> c;

//error-checking loop to ensure that user enters valid data, here
//meaning a lowercase letter:
cin >> c;
while (!islower(c)) {//logical Not operator, reverse truth value
  cout << "Error.  Must be lowercase. Reenter: ";
  cin >> c;
Next (string)
©2000 David Wills