09-C-Strings - ECE 175: Computer Programming for...

Info iconThis preview shows pages 1–5. Sign up to view the full content.

View Full Document Right Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: ECE 175: Computer Programming for Engineering Applications Strings ECE 175: Computer Programming for Engineering Applications - Strings String basics String: An array of characters We have seen the use of strings in scanf and printf statements before Specified within double quotes (" ") You may also use #define directive for strings Declaring and initializing string variables Similar to integer arrays, but simpler! Strings are terminated by \0 (null character) Array size must include the null character 2 Example: #define HELLOWORLD "Hello World \n" ... printf(HELLOWORLD); ... Example: char x[8] = "Hello"; H x[0] e x[1] l x[2] l x[3] o x[4] \0 x[5] ? x[6] ? x[7] ECE 175: Computer Programming for Engineering Applications - Strings String basics Arrays of strings Two dimensional array of characters Printing string variables Use %s in printf statements Formatting is similar to other variables Positive numbers right justify, negative numbers left-justify 3 Example: char months[12][15] = {"January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"}; Example: char hello[12] = "Hello World"; printf("%s\n", hello); printf("The first month is %s\n", months[0]); ECE 175: Computer Programming for Engineering Applications - Strings Getting string inputs Getting string input using scanf statement...
View Full Document

This note was uploaded on 04/10/2008 for the course ECE 175 taught by Professor Grubbs during the Spring '08 term at University of Arizona- Tucson.

Page1 / 11

09-C-Strings - ECE 175: Computer Programming for...

This preview shows document pages 1 - 5. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online