{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

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

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

View Full Document Right Arrow Icon
ECE 175: Computer Programming for Engineering Applications Strings
Image of page 1

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

View Full Document Right Arrow Icon
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]
Image of page 2
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]);
Image of page 3

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

View Full Document Right Arrow Icon
ECE 175: Computer Programming for Engineering Applications - Strings Getting string inputs Getting string input using scanf statement Similar to printf, use %s
Image of page 4
Image of page 5
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern