CISC 181 Introduction to Computer Science Dr. Mc. Coy Lecture 13 October 13, 2009 1
Repeated Slides • Some of the following slides are repeated from lecture 8 – character strings/character arrays 2
Storing Strings in Character Arrays • Character arrays may be initialized using a string literal: Char name[ ] = “Jane”; Initializes the char array “name” to hold the individual characters J-a-n-e plus a special string termination character called the null character writte ‘ ’ So, name is a 5 character array. 3
Strings in Character Arrays • An alternative: char name[ ] = {‘J’, ‘a’, ‘n’, ‘e’, ‘ ’}; • Common mistake – when using a char array to hold strings, forgetting to leave the extra spot for the null termination character. 4
5 4. 4 Examples Using Arrays • Strings (more in ch. 5) KFM – note Ch 9 in Savitch – Arrays of characters – All strings end with null ('