Lessons from CST exercise - PowerPoint PPT Presentation

About This Presentation
Title:

Lessons from CST exercise

Description:

string declaration. include string library. used defined ... A| |s|t|r|i|n|g| | 'hardwire' at declaration. use strcpy function // string initialization ... – PowerPoint PPT presentation

Number of Views:53
Avg rating:3.0/5.0
Slides: 9
Provided by: jackp3
Learn more at: https://sites.pitt.edu
Category:
Tags: cst | exercise | lessons | string

less

Transcript and Presenter's Notes

Title: Lessons from CST exercise


1
Engr 0012 (04-1) LecNotes 24-01
2
strings
strings are an array of type char
memory map
Engr 0012 (04-1) LecNotes 24-02
3
strings
// include libraries include //
defined constants define MAXSTRING
11 main() // begin main // variable
declaration char string1 "A string"
char string25 char string3MAXSTRING
int numchar, order
string initialization
A string?
hi???
get it from the keyboard
Hi there!??
Hi?????????
Engr 0012 (04-1) LecNotes 24-03
4
strings
string display
// displaying strings printf( "\n\nstring1
s", string1 ) printf( "\n\nstring2
s", string2 ) printf( "\n\nstring3 s",
string3 )
string placeholder is s
string1 A string string2 hi string3 Hi
there!
Engr 0012 (04-1) LecNotes 24-04
5
strings
copying strings - strcpy
// copying strings strcpy( string3,
string1) printf( "\n\nstring1 s",
string2 ) printf( "\n\nstring3 s",
string3 )
copies contents of second argument into first
argument
copies string1 into string3
Engr 0012 (04-1) LecNotes 24-05
6
strings
string length - strlen
// string length numchar strlen( string3
) printf("\n\nnum char in \"s\" d",
string3, numchar )
strlen counts characters until NULL is reached
Engr 0012 (04-1) LecNotes 24-06
7
strings
comparing strings - strcmp
// compare strings order strcmp( string1,
string2) if ( order "\n\ns before s", string1, string2 )
else if ( order 0 ) printf( "\n\ns
equals s", string1, string2 ) else
printf( "\n\ns after s", string1, string2 )

strcmp determines alphabetical order of two
strings
Engr 0012 (04-1) LecNotes 24-07
8
strings
parameters in function calls
strings are an array of type char
parameter useage follows same rules as any array
Engr 0012 (04-1) LecNotes 24-08
Write a Comment
User Comments (0)
About PowerShow.com