Lecture11_handout

Lecture11_handout - Overview Declare strings String input...

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

View Full Document Right Arrow Icon
1 EE140: Introduction to 0t o d u c t o t o Programming Concepts for Engineers Lecture 11 1 Strings Overview Declare strings tring input and output functions String input and output functions gets() and puts() Character input and output functions getchar() and putchar() Strings manipulating functions #include <string.h> 2 Strings A string is a series of characters treated as a single unit Strings in C are represented as arrays of characters char name[8]="Welcome"; first character --> element 0 of the array second character --> element 1 of the array ..... a special null character ‘\0’ is added in the end d t t t i fht dht 3 In order to store a string of n characters, we need a character array of size n+1. Element We l c ome\ 0 [0] [1] [2] [3] [4] [5] [6] [7] Declaration of string /* string of known fixed length */ char name1[8]; //empty string char name1[8]="Welcome"; //string with initial value /* let compiler determinate the size for you */ char name2[ ] = “Welcome"; /* declare string with variable length*/ char *name3; 4 //name3 is a pointer to string, your will learn it in EE150 /*declare a constant string that cannot be modified */ const char name4[10]="students";
Background image of page 1

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

View Full DocumentRight Arrow Icon
2 Example 1 #include <stdio.h> int main(void) { char str[10]="Textbook"; // create a text string printf("%s\n", str); // display the string printf("%c\n", str[3]); //display which character? str[4]='\0'; printf("%s\n", str); //what will be displayed?
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 09/04/2011 for the course EE 150 taught by Professor Lanxiang during the Spring '11 term at Montgomery College.

Page1 / 5

Lecture11_handout - Overview Declare strings String input...

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

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