{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

C By Discovery (4th Edition)

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

View Full Document Right Arrow Icon
1 Intermediate Programming CSE 1320 Lecture 10 Chapter 5: 5.1-5.3 Introduction to Strings Sequence of characters terminated by ‘\0’ String constants: inside double quotes (“) “CSE1320” printf(“CSE1320”); C S E 1 3 2 0 \0 String vs Array of Characters Array of characters – A string must have a null character as the string terminator while a character array does not require the ‘\0’ Pointer to a character char *char_ptr; char_ptr = “CSE1320”; printf(char_ptr); String Indexing Array indexing char_ptr[0] == ‘C’ char_ptr[3] == ‘1’ Pointer arithmetic and dereferencing *char_ptr == ‘C’ *(char_ptr+6) == ‘0’ printf and scanf printf(“String is %s\n”, char_ptr); scanf(“%s”, char_array); – Parameter is the address of an array with enough space to handle the input – First sequence of characters that does not contain a whitespace character. – Input leaves the first whitespace character in the input buffer H e l l o C S E 1 3 2 0 \n C S E 1 3 2 0 \n Input Buffer H e l l o \0
Background image of page 1

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

View Full Document Right Arrow Icon
Image of page 2
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}