SlideShare une entreprise Scribd logo
1  sur  38
Computer Science: A Structured Programming Approach Using C 1
11-2 C Strings
A C string is a variable-length array of characters that
is delimited by the null character.
Storing Strings
The String Delimiter
String Literals
Strings and Characters
Declaring Strings
Initializing Strings
Strings and the Assignment Operator
Reading and Writing Strings
Topics discussed in this section:
Computer Science: A Structured Programming Approach Using C 2
FIGURE 11-3 Storing Strings
Computer Science: A Structured Programming Approach Using C 3
FIGURE 11-4 Storing Strings and Characters
Computer Science: A Structured Programming Approach Using C 4
FIGURE 11-5 Differences Between Strings and Character Arrays
Computer Science: A Structured Programming Approach Using C 5
FIGURE 11-6 Strings in Arrays
Computer Science: A Structured Programming Approach Using C 6
A string literal is enclosed in double quotes.
Note
Computer Science: A Structured Programming Approach Using C 7
FIGURE 11-7 Character Literals and String Literals
Computer Science: A Structured Programming Approach Using C 8
FIGURE 11-8 String Literal References
Computer Science: A Structured Programming Approach Using C 9
FIGURE 11-9 Defining Strings
Computer Science: A Structured Programming Approach Using C 10
Memory for strings must be allocated before the
string can be used.
Note
Computer Science: A Structured Programming Approach Using C 11
FIGURE 11-10 Initializing Strings
Computer Science: A Structured Programming Approach Using C 12
11-3 String Input/Output Functions
C provides two basic ways to read and write strings.
First, we can read and write strings with the formatted
input/output functions, scanf/fscanf and printf/fprintf.
Second, we can use a special set of string-only functions,
get string (gets/fgets) and put string ( puts/fputs ).
Formatted String Input/Output
String Input/Output
Topics discussed in this section:
Computer Science: A Structured Programming Approach Using C 13
The string conversion code(s) skips whitespace.
Note
Computer Science: A Structured Programming Approach Using C 14
PROGRAM 11-1 Reading Strings
Computer Science: A Structured Programming Approach Using C 15
Always use a width in the field specification
when reading strings.
Note
Computer Science: A Structured Programming Approach Using C 16
The maximum number of characters to be printed
is specified by the precision in the format
string of the field specification.
Note
Computer Science: A Structured Programming Approach Using C 17
PROGRAM 11-2 Demonstrate String Scan Set
Computer Science: A Structured Programming Approach Using C 18
PROGRAM 11-2 Demonstrate String Scan Set
Computer Science: A Structured Programming Approach Using C 19
PROGRAM 11-3 Delete Leading Whitespace
Computer Science: A Structured Programming Approach Using C 20
PROGRAM 11-3 Delete Leading Whitespace
Computer Science: A Structured Programming Approach Using C 21
PROGRAM 11-4 Read Student Names and Scores
Computer Science: A Structured Programming Approach Using C 22
PROGRAM 11-4 Read Student Names and Scores
Computer Science: A Structured Programming Approach Using C 23
FIGURE 11-11 gets and fgets Functions
Computer Science: A Structured Programming Approach Using C 24
PROGRAM 11-5 Demonstrate fgets Operation
Computer Science: A Structured Programming Approach Using C 25
PROGRAM 11-5 Demonstrate fgets Operation
Computer Science: A Structured Programming Approach Using C 26
FIGURE 11-12 puts and fputs Operations
Computer Science: A Structured Programming Approach Using C 27
PROGRAM 11-6 Demonstration of Put String
Computer Science: A Structured Programming Approach Using C 28
PROGRAM 11-6 Demonstration of Put String
Computer Science: A Structured Programming Approach Using C 29
PROGRAM 11-7 Typewriter Program
Computer Science: A Structured Programming Approach Using C 30
PROGRAM 11-7 Typewriter Program
Computer Science: A Structured Programming Approach Using C 31
PROGRAM 11-8 Print Selected Sentences
Computer Science: A Structured Programming Approach Using C 32
PROGRAM 11-8 Print Selected Sentences
Computer Science: A Structured Programming Approach Using C 33
PROGRAM 11-9 Print File Double spaced
Computer Science: A Structured Programming Approach Using C 34
PROGRAM 11-9 Print File Double spaced
Computer Science: A Structured Programming Approach Using C 35
11-4 Arrays of Strings
When we discussed arrays of pointers in Chapter 10,
we introduced the concept of a ragged array. Ragged
arrays are very common with strings. Consider, for
example, the need to store the days of the week in their
textual format. We could create a two-dimensional
array of seven days by ten characters, but this wastes
space.
Computer Science: A Structured Programming Approach Using C 36
PROGRAM 11-10 Print Days of the Week
Computer Science: A Structured Programming Approach Using C 37
PROGRAM 11-10 Print Days of the Week
Computer Science: A Structured Programming Approach Using C 38
FIGURE 11-13 Pointers to Strings

Contenu connexe

Tendances

Intermediate code generation in Compiler Design
Intermediate code generation in Compiler DesignIntermediate code generation in Compiler Design
Intermediate code generation in Compiler DesignKuppusamy P
 
Java conceptual learning material
Java conceptual learning materialJava conceptual learning material
Java conceptual learning materialArthyR3
 
17432 object oriented programming
17432   object oriented programming17432   object oriented programming
17432 object oriented programmingsoni_nits
 
instruction format and addressing modes
instruction format and addressing modesinstruction format and addressing modes
instruction format and addressing modesRamaPrabha24
 
Register allocation and assignment
Register allocation and assignmentRegister allocation and assignment
Register allocation and assignmentKarthi Keyan
 
Intermediate code- generation
Intermediate code- generationIntermediate code- generation
Intermediate code- generationrawan_z
 
Issues in the design of Code Generator
Issues in the design of Code GeneratorIssues in the design of Code Generator
Issues in the design of Code GeneratorDarshan sai Reddy
 
Pict: A programming language based on the pi-calculus
Pict: A programming language based on the pi-calculusPict: A programming language based on the pi-calculus
Pict: A programming language based on the pi-calculusIMDS2014
 
Code optimization in compiler design
Code optimization in compiler designCode optimization in compiler design
Code optimization in compiler designKuppusamy P
 
A nice 64-bit error in C
A  nice 64-bit error in CA  nice 64-bit error in C
A nice 64-bit error in CPVS-Studio
 
Intermediate code representations
Intermediate code representationsIntermediate code representations
Intermediate code representationsahmed51236
 
Types of Instruction Format
Types of Instruction FormatTypes of Instruction Format
Types of Instruction FormatDhrumil Panchal
 
Issues in design_of_code_generator
Issues in design_of_code_generatorIssues in design_of_code_generator
Issues in design_of_code_generatorvinithapanneer
 
Unit 1 of c++ part 1 basic introduction
Unit 1 of c++ part 1 basic introductionUnit 1 of c++ part 1 basic introduction
Unit 1 of c++ part 1 basic introductionAKR Education
 

Tendances (20)

Intermediate code generation in Compiler Design
Intermediate code generation in Compiler DesignIntermediate code generation in Compiler Design
Intermediate code generation in Compiler Design
 
Java conceptual learning material
Java conceptual learning materialJava conceptual learning material
Java conceptual learning material
 
Compiler unit 4
Compiler unit 4Compiler unit 4
Compiler unit 4
 
17432 object oriented programming
17432   object oriented programming17432   object oriented programming
17432 object oriented programming
 
instruction format and addressing modes
instruction format and addressing modesinstruction format and addressing modes
instruction format and addressing modes
 
Register allocation and assignment
Register allocation and assignmentRegister allocation and assignment
Register allocation and assignment
 
Ch 6 qbank
Ch 6 qbankCh 6 qbank
Ch 6 qbank
 
Intermediate code- generation
Intermediate code- generationIntermediate code- generation
Intermediate code- generation
 
Issues in the design of Code Generator
Issues in the design of Code GeneratorIssues in the design of Code Generator
Issues in the design of Code Generator
 
Memory Reference Instructions
Memory Reference InstructionsMemory Reference Instructions
Memory Reference Instructions
 
Pict: A programming language based on the pi-calculus
Pict: A programming language based on the pi-calculusPict: A programming language based on the pi-calculus
Pict: A programming language based on the pi-calculus
 
Code optimization in compiler design
Code optimization in compiler designCode optimization in compiler design
Code optimization in compiler design
 
C basics
C basicsC basics
C basics
 
A nice 64-bit error in C
A  nice 64-bit error in CA  nice 64-bit error in C
A nice 64-bit error in C
 
Intermediate code representations
Intermediate code representationsIntermediate code representations
Intermediate code representations
 
Ch8a
Ch8aCh8a
Ch8a
 
Types of Instruction Format
Types of Instruction FormatTypes of Instruction Format
Types of Instruction Format
 
Issues in design_of_code_generator
Issues in design_of_code_generatorIssues in design_of_code_generator
Issues in design_of_code_generator
 
Unit iv(simple code generator)
Unit iv(simple code generator)Unit iv(simple code generator)
Unit iv(simple code generator)
 
Unit 1 of c++ part 1 basic introduction
Unit 1 of c++ part 1 basic introductionUnit 1 of c++ part 1 basic introduction
Unit 1 of c++ part 1 basic introduction
 

Similaire à Chap 11-1 (20)

Chap-07-1.ppt
Chap-07-1.pptChap-07-1.ppt
Chap-07-1.ppt
 
Variable-intro.pptx
Variable-intro.pptxVariable-intro.pptx
Variable-intro.pptx
 
Chap-02-01.ppt
Chap-02-01.pptChap-02-01.ppt
Chap-02-01.ppt
 
Chap-02-1.ppt
Chap-02-1.pptChap-02-1.ppt
Chap-02-1.ppt
 
Chap-02-1.ppt
Chap-02-1.pptChap-02-1.ppt
Chap-02-1.ppt
 
Chap-02-1.ppt
Chap-02-1.pptChap-02-1.ppt
Chap-02-1.ppt
 
Chap-02-1.ppt
Chap-02-1.pptChap-02-1.ppt
Chap-02-1.ppt
 
Chap-02-1.ppt
Chap-02-1.pptChap-02-1.ppt
Chap-02-1.ppt
 
Chap 02-1
Chap 02-1Chap 02-1
Chap 02-1
 
C programming-1.pptx
C programming-1.pptxC programming-1.pptx
C programming-1.pptx
 
Chapter 02-02.pptx
Chapter 02-02.pptxChapter 02-02.pptx
Chapter 02-02.pptx
 
Chap-02-1.ppt
Chap-02-1.pptChap-02-1.ppt
Chap-02-1.ppt
 
Chap-08-4.ppt
Chap-08-4.pptChap-08-4.ppt
Chap-08-4.ppt
 
Sample Programs.ppt
Sample Programs.pptSample Programs.ppt
Sample Programs.ppt
 
Lecture6
Lecture6Lecture6
Lecture6
 
Cs8251 faq1
Cs8251 faq1Cs8251 faq1
Cs8251 faq1
 
Intro
IntroIntro
Intro
 
Stack implementations
Stack implementationsStack implementations
Stack implementations
 
Chap-03-1.ppt
Chap-03-1.pptChap-03-1.ppt
Chap-03-1.ppt
 
Stack implementation using c
Stack implementation using cStack implementation using c
Stack implementation using c
 

Dernier

Q4-W4-SCIENCE-5 power point presentation
Q4-W4-SCIENCE-5 power point presentationQ4-W4-SCIENCE-5 power point presentation
Q4-W4-SCIENCE-5 power point presentationZenSeloveres
 
Gamestore case study UI UX by Amgad Ibrahim
Gamestore case study UI UX by Amgad IbrahimGamestore case study UI UX by Amgad Ibrahim
Gamestore case study UI UX by Amgad Ibrahimamgadibrahim92
 
Jigani Call Girls Service: 🍓 7737669865 🍓 High Profile Model Escorts | Bangal...
Jigani Call Girls Service: 🍓 7737669865 🍓 High Profile Model Escorts | Bangal...Jigani Call Girls Service: 🍓 7737669865 🍓 High Profile Model Escorts | Bangal...
Jigani Call Girls Service: 🍓 7737669865 🍓 High Profile Model Escorts | Bangal...amitlee9823
 
Call Girls Basavanagudi Just Call 👗 7737669865 👗 Top Class Call Girl Service ...
Call Girls Basavanagudi Just Call 👗 7737669865 👗 Top Class Call Girl Service ...Call Girls Basavanagudi Just Call 👗 7737669865 👗 Top Class Call Girl Service ...
Call Girls Basavanagudi Just Call 👗 7737669865 👗 Top Class Call Girl Service ...amitlee9823
 
Whitefield Call Girls Service: 🍓 7737669865 🍓 High Profile Model Escorts | Ba...
Whitefield Call Girls Service: 🍓 7737669865 🍓 High Profile Model Escorts | Ba...Whitefield Call Girls Service: 🍓 7737669865 🍓 High Profile Model Escorts | Ba...
Whitefield Call Girls Service: 🍓 7737669865 🍓 High Profile Model Escorts | Ba...amitlee9823
 
Just Call Vip call girls Etawah Escorts ☎️9352988975 Two shot with one girl (...
Just Call Vip call girls Etawah Escorts ☎️9352988975 Two shot with one girl (...Just Call Vip call girls Etawah Escorts ☎️9352988975 Two shot with one girl (...
Just Call Vip call girls Etawah Escorts ☎️9352988975 Two shot with one girl (...gajnagarg
 
➥🔝 7737669865 🔝▻ dehradun Call-girls in Women Seeking Men 🔝dehradun🔝 Escor...
➥🔝 7737669865 🔝▻ dehradun Call-girls in Women Seeking Men  🔝dehradun🔝   Escor...➥🔝 7737669865 🔝▻ dehradun Call-girls in Women Seeking Men  🔝dehradun🔝   Escor...
➥🔝 7737669865 🔝▻ dehradun Call-girls in Women Seeking Men 🔝dehradun🔝 Escor...amitlee9823
 
Jordan_Amanda_DMBS202404_PB1_2024-04.pdf
Jordan_Amanda_DMBS202404_PB1_2024-04.pdfJordan_Amanda_DMBS202404_PB1_2024-04.pdf
Jordan_Amanda_DMBS202404_PB1_2024-04.pdfamanda2495
 
High Profile Escorts Nerul WhatsApp +91-9930687706, Best Service
High Profile Escorts Nerul WhatsApp +91-9930687706, Best ServiceHigh Profile Escorts Nerul WhatsApp +91-9930687706, Best Service
High Profile Escorts Nerul WhatsApp +91-9930687706, Best Servicemeghakumariji156
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️Delhi Call girls
 
RT Nagar Call Girls Service: 🍓 7737669865 🍓 High Profile Model Escorts | Bang...
RT Nagar Call Girls Service: 🍓 7737669865 🍓 High Profile Model Escorts | Bang...RT Nagar Call Girls Service: 🍓 7737669865 🍓 High Profile Model Escorts | Bang...
RT Nagar Call Girls Service: 🍓 7737669865 🍓 High Profile Model Escorts | Bang...amitlee9823
 
UI:UX Design and Empowerment Strategies for Underprivileged Transgender Indiv...
UI:UX Design and Empowerment Strategies for Underprivileged Transgender Indiv...UI:UX Design and Empowerment Strategies for Underprivileged Transgender Indiv...
UI:UX Design and Empowerment Strategies for Underprivileged Transgender Indiv...RitikaRoy32
 
❤Personal Whatsapp Number 8617697112 Samba Call Girls 💦✅.
❤Personal Whatsapp Number 8617697112 Samba Call Girls 💦✅.❤Personal Whatsapp Number 8617697112 Samba Call Girls 💦✅.
❤Personal Whatsapp Number 8617697112 Samba Call Girls 💦✅.Nitya salvi
 
Hingoli ❤CALL GIRL 8617370543 ❤CALL GIRLS IN Hingoli ESCORT SERVICE❤CALL GIRL
Hingoli ❤CALL GIRL 8617370543 ❤CALL GIRLS IN Hingoli ESCORT SERVICE❤CALL GIRLHingoli ❤CALL GIRL 8617370543 ❤CALL GIRLS IN Hingoli ESCORT SERVICE❤CALL GIRL
Hingoli ❤CALL GIRL 8617370543 ❤CALL GIRLS IN Hingoli ESCORT SERVICE❤CALL GIRLNitya salvi
 
Vip Mumbai Call Girls Borivali Call On 9920725232 With Body to body massage w...
Vip Mumbai Call Girls Borivali Call On 9920725232 With Body to body massage w...Vip Mumbai Call Girls Borivali Call On 9920725232 With Body to body massage w...
Vip Mumbai Call Girls Borivali Call On 9920725232 With Body to body massage w...amitlee9823
 
Anupama Kundoo Cost Effective detailed ppt with plans and elevations with det...
Anupama Kundoo Cost Effective detailed ppt with plans and elevations with det...Anupama Kundoo Cost Effective detailed ppt with plans and elevations with det...
Anupama Kundoo Cost Effective detailed ppt with plans and elevations with det...sriharipichandi
 
Escorts Service Basapura ☎ 7737669865☎ Book Your One night Stand (Bangalore)
Escorts Service Basapura ☎ 7737669865☎ Book Your One night Stand (Bangalore)Escorts Service Basapura ☎ 7737669865☎ Book Your One night Stand (Bangalore)
Escorts Service Basapura ☎ 7737669865☎ Book Your One night Stand (Bangalore)amitlee9823
 
Pooja 9892124323, Call girls Services and Mumbai Escort Service Near Hotel Gi...
Pooja 9892124323, Call girls Services and Mumbai Escort Service Near Hotel Gi...Pooja 9892124323, Call girls Services and Mumbai Escort Service Near Hotel Gi...
Pooja 9892124323, Call girls Services and Mumbai Escort Service Near Hotel Gi...Pooja Nehwal
 
Just Call Vip call girls dharamshala Escorts ☎️9352988975 Two shot with one g...
Just Call Vip call girls dharamshala Escorts ☎️9352988975 Two shot with one g...Just Call Vip call girls dharamshala Escorts ☎️9352988975 Two shot with one g...
Just Call Vip call girls dharamshala Escorts ☎️9352988975 Two shot with one g...gajnagarg
 
➥🔝 7737669865 🔝▻ dharamshala Call-girls in Women Seeking Men 🔝dharamshala🔝 ...
➥🔝 7737669865 🔝▻ dharamshala Call-girls in Women Seeking Men  🔝dharamshala🔝  ...➥🔝 7737669865 🔝▻ dharamshala Call-girls in Women Seeking Men  🔝dharamshala🔝  ...
➥🔝 7737669865 🔝▻ dharamshala Call-girls in Women Seeking Men 🔝dharamshala🔝 ...amitlee9823
 

Dernier (20)

Q4-W4-SCIENCE-5 power point presentation
Q4-W4-SCIENCE-5 power point presentationQ4-W4-SCIENCE-5 power point presentation
Q4-W4-SCIENCE-5 power point presentation
 
Gamestore case study UI UX by Amgad Ibrahim
Gamestore case study UI UX by Amgad IbrahimGamestore case study UI UX by Amgad Ibrahim
Gamestore case study UI UX by Amgad Ibrahim
 
Jigani Call Girls Service: 🍓 7737669865 🍓 High Profile Model Escorts | Bangal...
Jigani Call Girls Service: 🍓 7737669865 🍓 High Profile Model Escorts | Bangal...Jigani Call Girls Service: 🍓 7737669865 🍓 High Profile Model Escorts | Bangal...
Jigani Call Girls Service: 🍓 7737669865 🍓 High Profile Model Escorts | Bangal...
 
Call Girls Basavanagudi Just Call 👗 7737669865 👗 Top Class Call Girl Service ...
Call Girls Basavanagudi Just Call 👗 7737669865 👗 Top Class Call Girl Service ...Call Girls Basavanagudi Just Call 👗 7737669865 👗 Top Class Call Girl Service ...
Call Girls Basavanagudi Just Call 👗 7737669865 👗 Top Class Call Girl Service ...
 
Whitefield Call Girls Service: 🍓 7737669865 🍓 High Profile Model Escorts | Ba...
Whitefield Call Girls Service: 🍓 7737669865 🍓 High Profile Model Escorts | Ba...Whitefield Call Girls Service: 🍓 7737669865 🍓 High Profile Model Escorts | Ba...
Whitefield Call Girls Service: 🍓 7737669865 🍓 High Profile Model Escorts | Ba...
 
Just Call Vip call girls Etawah Escorts ☎️9352988975 Two shot with one girl (...
Just Call Vip call girls Etawah Escorts ☎️9352988975 Two shot with one girl (...Just Call Vip call girls Etawah Escorts ☎️9352988975 Two shot with one girl (...
Just Call Vip call girls Etawah Escorts ☎️9352988975 Two shot with one girl (...
 
➥🔝 7737669865 🔝▻ dehradun Call-girls in Women Seeking Men 🔝dehradun🔝 Escor...
➥🔝 7737669865 🔝▻ dehradun Call-girls in Women Seeking Men  🔝dehradun🔝   Escor...➥🔝 7737669865 🔝▻ dehradun Call-girls in Women Seeking Men  🔝dehradun🔝   Escor...
➥🔝 7737669865 🔝▻ dehradun Call-girls in Women Seeking Men 🔝dehradun🔝 Escor...
 
Jordan_Amanda_DMBS202404_PB1_2024-04.pdf
Jordan_Amanda_DMBS202404_PB1_2024-04.pdfJordan_Amanda_DMBS202404_PB1_2024-04.pdf
Jordan_Amanda_DMBS202404_PB1_2024-04.pdf
 
High Profile Escorts Nerul WhatsApp +91-9930687706, Best Service
High Profile Escorts Nerul WhatsApp +91-9930687706, Best ServiceHigh Profile Escorts Nerul WhatsApp +91-9930687706, Best Service
High Profile Escorts Nerul WhatsApp +91-9930687706, Best Service
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
 
RT Nagar Call Girls Service: 🍓 7737669865 🍓 High Profile Model Escorts | Bang...
RT Nagar Call Girls Service: 🍓 7737669865 🍓 High Profile Model Escorts | Bang...RT Nagar Call Girls Service: 🍓 7737669865 🍓 High Profile Model Escorts | Bang...
RT Nagar Call Girls Service: 🍓 7737669865 🍓 High Profile Model Escorts | Bang...
 
UI:UX Design and Empowerment Strategies for Underprivileged Transgender Indiv...
UI:UX Design and Empowerment Strategies for Underprivileged Transgender Indiv...UI:UX Design and Empowerment Strategies for Underprivileged Transgender Indiv...
UI:UX Design and Empowerment Strategies for Underprivileged Transgender Indiv...
 
❤Personal Whatsapp Number 8617697112 Samba Call Girls 💦✅.
❤Personal Whatsapp Number 8617697112 Samba Call Girls 💦✅.❤Personal Whatsapp Number 8617697112 Samba Call Girls 💦✅.
❤Personal Whatsapp Number 8617697112 Samba Call Girls 💦✅.
 
Hingoli ❤CALL GIRL 8617370543 ❤CALL GIRLS IN Hingoli ESCORT SERVICE❤CALL GIRL
Hingoli ❤CALL GIRL 8617370543 ❤CALL GIRLS IN Hingoli ESCORT SERVICE❤CALL GIRLHingoli ❤CALL GIRL 8617370543 ❤CALL GIRLS IN Hingoli ESCORT SERVICE❤CALL GIRL
Hingoli ❤CALL GIRL 8617370543 ❤CALL GIRLS IN Hingoli ESCORT SERVICE❤CALL GIRL
 
Vip Mumbai Call Girls Borivali Call On 9920725232 With Body to body massage w...
Vip Mumbai Call Girls Borivali Call On 9920725232 With Body to body massage w...Vip Mumbai Call Girls Borivali Call On 9920725232 With Body to body massage w...
Vip Mumbai Call Girls Borivali Call On 9920725232 With Body to body massage w...
 
Anupama Kundoo Cost Effective detailed ppt with plans and elevations with det...
Anupama Kundoo Cost Effective detailed ppt with plans and elevations with det...Anupama Kundoo Cost Effective detailed ppt with plans and elevations with det...
Anupama Kundoo Cost Effective detailed ppt with plans and elevations with det...
 
Escorts Service Basapura ☎ 7737669865☎ Book Your One night Stand (Bangalore)
Escorts Service Basapura ☎ 7737669865☎ Book Your One night Stand (Bangalore)Escorts Service Basapura ☎ 7737669865☎ Book Your One night Stand (Bangalore)
Escorts Service Basapura ☎ 7737669865☎ Book Your One night Stand (Bangalore)
 
Pooja 9892124323, Call girls Services and Mumbai Escort Service Near Hotel Gi...
Pooja 9892124323, Call girls Services and Mumbai Escort Service Near Hotel Gi...Pooja 9892124323, Call girls Services and Mumbai Escort Service Near Hotel Gi...
Pooja 9892124323, Call girls Services and Mumbai Escort Service Near Hotel Gi...
 
Just Call Vip call girls dharamshala Escorts ☎️9352988975 Two shot with one g...
Just Call Vip call girls dharamshala Escorts ☎️9352988975 Two shot with one g...Just Call Vip call girls dharamshala Escorts ☎️9352988975 Two shot with one g...
Just Call Vip call girls dharamshala Escorts ☎️9352988975 Two shot with one g...
 
➥🔝 7737669865 🔝▻ dharamshala Call-girls in Women Seeking Men 🔝dharamshala🔝 ...
➥🔝 7737669865 🔝▻ dharamshala Call-girls in Women Seeking Men  🔝dharamshala🔝  ...➥🔝 7737669865 🔝▻ dharamshala Call-girls in Women Seeking Men  🔝dharamshala🔝  ...
➥🔝 7737669865 🔝▻ dharamshala Call-girls in Women Seeking Men 🔝dharamshala🔝 ...
 

Chap 11-1

  • 1. Computer Science: A Structured Programming Approach Using C 1 11-2 C Strings A C string is a variable-length array of characters that is delimited by the null character. Storing Strings The String Delimiter String Literals Strings and Characters Declaring Strings Initializing Strings Strings and the Assignment Operator Reading and Writing Strings Topics discussed in this section:
  • 2. Computer Science: A Structured Programming Approach Using C 2 FIGURE 11-3 Storing Strings
  • 3. Computer Science: A Structured Programming Approach Using C 3 FIGURE 11-4 Storing Strings and Characters
  • 4. Computer Science: A Structured Programming Approach Using C 4 FIGURE 11-5 Differences Between Strings and Character Arrays
  • 5. Computer Science: A Structured Programming Approach Using C 5 FIGURE 11-6 Strings in Arrays
  • 6. Computer Science: A Structured Programming Approach Using C 6 A string literal is enclosed in double quotes. Note
  • 7. Computer Science: A Structured Programming Approach Using C 7 FIGURE 11-7 Character Literals and String Literals
  • 8. Computer Science: A Structured Programming Approach Using C 8 FIGURE 11-8 String Literal References
  • 9. Computer Science: A Structured Programming Approach Using C 9 FIGURE 11-9 Defining Strings
  • 10. Computer Science: A Structured Programming Approach Using C 10 Memory for strings must be allocated before the string can be used. Note
  • 11. Computer Science: A Structured Programming Approach Using C 11 FIGURE 11-10 Initializing Strings
  • 12. Computer Science: A Structured Programming Approach Using C 12 11-3 String Input/Output Functions C provides two basic ways to read and write strings. First, we can read and write strings with the formatted input/output functions, scanf/fscanf and printf/fprintf. Second, we can use a special set of string-only functions, get string (gets/fgets) and put string ( puts/fputs ). Formatted String Input/Output String Input/Output Topics discussed in this section:
  • 13. Computer Science: A Structured Programming Approach Using C 13 The string conversion code(s) skips whitespace. Note
  • 14. Computer Science: A Structured Programming Approach Using C 14 PROGRAM 11-1 Reading Strings
  • 15. Computer Science: A Structured Programming Approach Using C 15 Always use a width in the field specification when reading strings. Note
  • 16. Computer Science: A Structured Programming Approach Using C 16 The maximum number of characters to be printed is specified by the precision in the format string of the field specification. Note
  • 17. Computer Science: A Structured Programming Approach Using C 17 PROGRAM 11-2 Demonstrate String Scan Set
  • 18. Computer Science: A Structured Programming Approach Using C 18 PROGRAM 11-2 Demonstrate String Scan Set
  • 19. Computer Science: A Structured Programming Approach Using C 19 PROGRAM 11-3 Delete Leading Whitespace
  • 20. Computer Science: A Structured Programming Approach Using C 20 PROGRAM 11-3 Delete Leading Whitespace
  • 21. Computer Science: A Structured Programming Approach Using C 21 PROGRAM 11-4 Read Student Names and Scores
  • 22. Computer Science: A Structured Programming Approach Using C 22 PROGRAM 11-4 Read Student Names and Scores
  • 23. Computer Science: A Structured Programming Approach Using C 23 FIGURE 11-11 gets and fgets Functions
  • 24. Computer Science: A Structured Programming Approach Using C 24 PROGRAM 11-5 Demonstrate fgets Operation
  • 25. Computer Science: A Structured Programming Approach Using C 25 PROGRAM 11-5 Demonstrate fgets Operation
  • 26. Computer Science: A Structured Programming Approach Using C 26 FIGURE 11-12 puts and fputs Operations
  • 27. Computer Science: A Structured Programming Approach Using C 27 PROGRAM 11-6 Demonstration of Put String
  • 28. Computer Science: A Structured Programming Approach Using C 28 PROGRAM 11-6 Demonstration of Put String
  • 29. Computer Science: A Structured Programming Approach Using C 29 PROGRAM 11-7 Typewriter Program
  • 30. Computer Science: A Structured Programming Approach Using C 30 PROGRAM 11-7 Typewriter Program
  • 31. Computer Science: A Structured Programming Approach Using C 31 PROGRAM 11-8 Print Selected Sentences
  • 32. Computer Science: A Structured Programming Approach Using C 32 PROGRAM 11-8 Print Selected Sentences
  • 33. Computer Science: A Structured Programming Approach Using C 33 PROGRAM 11-9 Print File Double spaced
  • 34. Computer Science: A Structured Programming Approach Using C 34 PROGRAM 11-9 Print File Double spaced
  • 35. Computer Science: A Structured Programming Approach Using C 35 11-4 Arrays of Strings When we discussed arrays of pointers in Chapter 10, we introduced the concept of a ragged array. Ragged arrays are very common with strings. Consider, for example, the need to store the days of the week in their textual format. We could create a two-dimensional array of seven days by ten characters, but this wastes space.
  • 36. Computer Science: A Structured Programming Approach Using C 36 PROGRAM 11-10 Print Days of the Week
  • 37. Computer Science: A Structured Programming Approach Using C 37 PROGRAM 11-10 Print Days of the Week
  • 38. Computer Science: A Structured Programming Approach Using C 38 FIGURE 11-13 Pointers to Strings