SlideShare a Scribd company logo
1 of 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

More Related Content

What's hot

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
 

What's hot (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
 

Similar to 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
 

Recently uploaded

Dubai Call Girls Pro Domain O525547819 Call Girls Dubai Doux
Dubai Call Girls Pro Domain O525547819 Call Girls Dubai DouxDubai Call Girls Pro Domain O525547819 Call Girls Dubai Doux
Dubai Call Girls Pro Domain O525547819 Call Girls Dubai Douxkojalkojal131
 
Introduction-to-Canva-and-Graphic-Design-Basics.pptx
Introduction-to-Canva-and-Graphic-Design-Basics.pptxIntroduction-to-Canva-and-Graphic-Design-Basics.pptx
Introduction-to-Canva-and-Graphic-Design-Basics.pptxnewslab143
 
办理(宾州州立毕业证书)美国宾夕法尼亚州立大学毕业证成绩单原版一比一
办理(宾州州立毕业证书)美国宾夕法尼亚州立大学毕业证成绩单原版一比一办理(宾州州立毕业证书)美国宾夕法尼亚州立大学毕业证成绩单原版一比一
办理(宾州州立毕业证书)美国宾夕法尼亚州立大学毕业证成绩单原版一比一F La
 
SCRIP Lua HTTP PROGRACMACION PLC WECON CA
SCRIP Lua HTTP PROGRACMACION PLC  WECON CASCRIP Lua HTTP PROGRACMACION PLC  WECON CA
SCRIP Lua HTTP PROGRACMACION PLC WECON CANestorGamez6
 
Call Girls Satellite 7397865700 Ridhima Hire Me Full Night
Call Girls Satellite 7397865700 Ridhima Hire Me Full NightCall Girls Satellite 7397865700 Ridhima Hire Me Full Night
Call Girls Satellite 7397865700 Ridhima Hire Me Full Nightssuser7cb4ff
 
VIP Call Girls Service Bhagyanagar Hyderabad Call +91-8250192130
VIP Call Girls Service Bhagyanagar Hyderabad Call +91-8250192130VIP Call Girls Service Bhagyanagar Hyderabad Call +91-8250192130
VIP Call Girls Service Bhagyanagar Hyderabad Call +91-8250192130Suhani Kapoor
 
Architecture case study India Habitat Centre, Delhi.pdf
Architecture case study India Habitat Centre, Delhi.pdfArchitecture case study India Habitat Centre, Delhi.pdf
Architecture case study India Habitat Centre, Delhi.pdfSumit Lathwal
 
Cosumer Willingness to Pay for Sustainable Bricks
Cosumer Willingness to Pay for Sustainable BricksCosumer Willingness to Pay for Sustainable Bricks
Cosumer Willingness to Pay for Sustainable Bricksabhishekparmar618
 
Passbook project document_april_21__.pdf
Passbook project document_april_21__.pdfPassbook project document_april_21__.pdf
Passbook project document_april_21__.pdfvaibhavkanaujia
 
Revit Understanding Reference Planes and Reference lines in Revit for Family ...
Revit Understanding Reference Planes and Reference lines in Revit for Family ...Revit Understanding Reference Planes and Reference lines in Revit for Family ...
Revit Understanding Reference Planes and Reference lines in Revit for Family ...Narsimha murthy
 
Abu Dhabi Call Girls O58993O4O2 Call Girls in Abu Dhabi`
Abu Dhabi Call Girls O58993O4O2 Call Girls in Abu Dhabi`Abu Dhabi Call Girls O58993O4O2 Call Girls in Abu Dhabi`
Abu Dhabi Call Girls O58993O4O2 Call Girls in Abu Dhabi`dajasot375
 
306MTAMount UCLA University Bachelor's Diploma in Social Media
306MTAMount UCLA University Bachelor's Diploma in Social Media306MTAMount UCLA University Bachelor's Diploma in Social Media
306MTAMount UCLA University Bachelor's Diploma in Social MediaD SSS
 
办理学位证(NUS证书)新加坡国立大学毕业证成绩单原版一比一
办理学位证(NUS证书)新加坡国立大学毕业证成绩单原版一比一办理学位证(NUS证书)新加坡国立大学毕业证成绩单原版一比一
办理学位证(NUS证书)新加坡国立大学毕业证成绩单原版一比一Fi L
 
Housewife Call Girls NRI Layout - Call 7001305949 Rs-3500 with A/C Room Cash ...
Housewife Call Girls NRI Layout - Call 7001305949 Rs-3500 with A/C Room Cash ...Housewife Call Girls NRI Layout - Call 7001305949 Rs-3500 with A/C Room Cash ...
Housewife Call Girls NRI Layout - Call 7001305949 Rs-3500 with A/C Room Cash ...narwatsonia7
 
ARt app | UX Case Study
ARt app | UX Case StudyARt app | UX Case Study
ARt app | UX Case StudySophia Viganò
 
定制(RMIT毕业证书)澳洲墨尔本皇家理工大学毕业证成绩单原版一比一
定制(RMIT毕业证书)澳洲墨尔本皇家理工大学毕业证成绩单原版一比一定制(RMIT毕业证书)澳洲墨尔本皇家理工大学毕业证成绩单原版一比一
定制(RMIT毕业证书)澳洲墨尔本皇家理工大学毕业证成绩单原版一比一lvtagr7
 
VIP Call Girl Amravati Aashi 8250192130 Independent Escort Service Amravati
VIP Call Girl Amravati Aashi 8250192130 Independent Escort Service AmravatiVIP Call Girl Amravati Aashi 8250192130 Independent Escort Service Amravati
VIP Call Girl Amravati Aashi 8250192130 Independent Escort Service AmravatiSuhani Kapoor
 
WAEC Carpentry and Joinery Past Questions
WAEC Carpentry and Joinery Past QuestionsWAEC Carpentry and Joinery Past Questions
WAEC Carpentry and Joinery Past QuestionsCharles Obaleagbon
 
Call Girls In Safdarjung Enclave 24/7✡️9711147426✡️ Escorts Service
Call Girls In Safdarjung Enclave 24/7✡️9711147426✡️ Escorts ServiceCall Girls In Safdarjung Enclave 24/7✡️9711147426✡️ Escorts Service
Call Girls In Safdarjung Enclave 24/7✡️9711147426✡️ Escorts Servicejennyeacort
 

Recently uploaded (20)

Call Girls in Pratap Nagar, 9953056974 Escort Service
Call Girls in Pratap Nagar,  9953056974 Escort ServiceCall Girls in Pratap Nagar,  9953056974 Escort Service
Call Girls in Pratap Nagar, 9953056974 Escort Service
 
Dubai Call Girls Pro Domain O525547819 Call Girls Dubai Doux
Dubai Call Girls Pro Domain O525547819 Call Girls Dubai DouxDubai Call Girls Pro Domain O525547819 Call Girls Dubai Doux
Dubai Call Girls Pro Domain O525547819 Call Girls Dubai Doux
 
Introduction-to-Canva-and-Graphic-Design-Basics.pptx
Introduction-to-Canva-and-Graphic-Design-Basics.pptxIntroduction-to-Canva-and-Graphic-Design-Basics.pptx
Introduction-to-Canva-and-Graphic-Design-Basics.pptx
 
办理(宾州州立毕业证书)美国宾夕法尼亚州立大学毕业证成绩单原版一比一
办理(宾州州立毕业证书)美国宾夕法尼亚州立大学毕业证成绩单原版一比一办理(宾州州立毕业证书)美国宾夕法尼亚州立大学毕业证成绩单原版一比一
办理(宾州州立毕业证书)美国宾夕法尼亚州立大学毕业证成绩单原版一比一
 
SCRIP Lua HTTP PROGRACMACION PLC WECON CA
SCRIP Lua HTTP PROGRACMACION PLC  WECON CASCRIP Lua HTTP PROGRACMACION PLC  WECON CA
SCRIP Lua HTTP PROGRACMACION PLC WECON CA
 
Call Girls Satellite 7397865700 Ridhima Hire Me Full Night
Call Girls Satellite 7397865700 Ridhima Hire Me Full NightCall Girls Satellite 7397865700 Ridhima Hire Me Full Night
Call Girls Satellite 7397865700 Ridhima Hire Me Full Night
 
VIP Call Girls Service Bhagyanagar Hyderabad Call +91-8250192130
VIP Call Girls Service Bhagyanagar Hyderabad Call +91-8250192130VIP Call Girls Service Bhagyanagar Hyderabad Call +91-8250192130
VIP Call Girls Service Bhagyanagar Hyderabad Call +91-8250192130
 
Architecture case study India Habitat Centre, Delhi.pdf
Architecture case study India Habitat Centre, Delhi.pdfArchitecture case study India Habitat Centre, Delhi.pdf
Architecture case study India Habitat Centre, Delhi.pdf
 
Cosumer Willingness to Pay for Sustainable Bricks
Cosumer Willingness to Pay for Sustainable BricksCosumer Willingness to Pay for Sustainable Bricks
Cosumer Willingness to Pay for Sustainable Bricks
 
Passbook project document_april_21__.pdf
Passbook project document_april_21__.pdfPassbook project document_april_21__.pdf
Passbook project document_april_21__.pdf
 
Revit Understanding Reference Planes and Reference lines in Revit for Family ...
Revit Understanding Reference Planes and Reference lines in Revit for Family ...Revit Understanding Reference Planes and Reference lines in Revit for Family ...
Revit Understanding Reference Planes and Reference lines in Revit for Family ...
 
Abu Dhabi Call Girls O58993O4O2 Call Girls in Abu Dhabi`
Abu Dhabi Call Girls O58993O4O2 Call Girls in Abu Dhabi`Abu Dhabi Call Girls O58993O4O2 Call Girls in Abu Dhabi`
Abu Dhabi Call Girls O58993O4O2 Call Girls in Abu Dhabi`
 
306MTAMount UCLA University Bachelor's Diploma in Social Media
306MTAMount UCLA University Bachelor's Diploma in Social Media306MTAMount UCLA University Bachelor's Diploma in Social Media
306MTAMount UCLA University Bachelor's Diploma in Social Media
 
办理学位证(NUS证书)新加坡国立大学毕业证成绩单原版一比一
办理学位证(NUS证书)新加坡国立大学毕业证成绩单原版一比一办理学位证(NUS证书)新加坡国立大学毕业证成绩单原版一比一
办理学位证(NUS证书)新加坡国立大学毕业证成绩单原版一比一
 
Housewife Call Girls NRI Layout - Call 7001305949 Rs-3500 with A/C Room Cash ...
Housewife Call Girls NRI Layout - Call 7001305949 Rs-3500 with A/C Room Cash ...Housewife Call Girls NRI Layout - Call 7001305949 Rs-3500 with A/C Room Cash ...
Housewife Call Girls NRI Layout - Call 7001305949 Rs-3500 with A/C Room Cash ...
 
ARt app | UX Case Study
ARt app | UX Case StudyARt app | UX Case Study
ARt app | UX Case Study
 
定制(RMIT毕业证书)澳洲墨尔本皇家理工大学毕业证成绩单原版一比一
定制(RMIT毕业证书)澳洲墨尔本皇家理工大学毕业证成绩单原版一比一定制(RMIT毕业证书)澳洲墨尔本皇家理工大学毕业证成绩单原版一比一
定制(RMIT毕业证书)澳洲墨尔本皇家理工大学毕业证成绩单原版一比一
 
VIP Call Girl Amravati Aashi 8250192130 Independent Escort Service Amravati
VIP Call Girl Amravati Aashi 8250192130 Independent Escort Service AmravatiVIP Call Girl Amravati Aashi 8250192130 Independent Escort Service Amravati
VIP Call Girl Amravati Aashi 8250192130 Independent Escort Service Amravati
 
WAEC Carpentry and Joinery Past Questions
WAEC Carpentry and Joinery Past QuestionsWAEC Carpentry and Joinery Past Questions
WAEC Carpentry and Joinery Past Questions
 
Call Girls In Safdarjung Enclave 24/7✡️9711147426✡️ Escorts Service
Call Girls In Safdarjung Enclave 24/7✡️9711147426✡️ Escorts ServiceCall Girls In Safdarjung Enclave 24/7✡️9711147426✡️ Escorts Service
Call Girls In Safdarjung Enclave 24/7✡️9711147426✡️ Escorts Service
 

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