SlideShare a Scribd company logo
1 of 11
C - String
C - String
• strings are arrays of chars. String literals are words surrounded by double
quotation marks.
• The string in C programming language is actually a one-dimensional array
of characters which is terminated by a null character '0'. Thus a null-
terminated string contains the characters that comprise the string followed
by a null.
• A string can be declared as a character array or with a string pointer.
• The following declaration and initialization create a string consisting of the
word "Hello". To hold the null character at the end of the array, the size of
the character array containing the string is one more than the number of
characters in the word "Hello."
"This is a static string"
Or
Or
char *greeting = “Hello” ;
C - String
• Following is the memory presentation of above defined string in C/C++:
 It's important to remember that there will be an extra character on
the end on a string, literally a '0' character, just like there is always a
period at the end of a sentence. Since this string terminator is
unprintable, it is not counted as a letter, but it still takes up a space.
Technically, in a fifty char array you could only hold 49 letters and
one null character at the end to terminate the string.
 Actually, you do not place the null character at the end of a string
constant. The C compiler automatically places the '0' at the end of
the string when it initializes the array.
C - String
• Let us try to print above mentioned string:
 Note: %s is used to print a string.
String pointer
• String pointers are declared as a pointer to a char.
• When there is a value assigned to the string pointer the NULL is put
at the end automatically.
• Take a look at this example:
String pointer
• It is not possible to read, with scanf(), a string with a string pointer.
You have to use a character array and a pointer. See this example:
Reading a line of text
gets() and puts() are two string functions to take string input from
user and display string respectively
String related operations
• Find the Frequency of Characters in a String
• Find the Number of Vowels, Consonants, Digits and White space in a
String
• Reverse a String by Passing it to Function
• Find the Length of a String
• Concatenate Two Strings
• Copy a String
• Remove all Characters in a String except alphabet
• Sort a string in alphabetic order
• Sort Elements in Lexicographical Order (Dictionary Order)
• Change Decimal to Hexadecimal Number
• Convert Binary Number to Decimal
Copy String Manually
You can use the strcpy( )
function to copy the content of
one string to another but, this
program copies the content of
one string to another manually
without using strcpy( ) function.
C library functions
• C supports a wide range of functions that manipulate null-terminated
strings:
C - String ppt

More Related Content

What's hot

strings in c language and its importance
strings in c language and its importancestrings in c language and its importance
strings in c language and its importancesirmanohar
 
Strings in C language
Strings in C languageStrings in C language
Strings in C languageP M Patil
 
Regex Presentation
Regex PresentationRegex Presentation
Regex Presentationarnolambert
 
C programming language character set keywords constants variables data types
C programming language character set keywords constants variables data typesC programming language character set keywords constants variables data types
C programming language character set keywords constants variables data typesSourav Ganguly
 
Regular Expression
Regular ExpressionRegular Expression
Regular ExpressionLambert Lum
 
Regular expressions
Regular expressionsRegular expressions
Regular expressionsRaj Gupta
 
Introduction to regular expressions
Introduction to regular expressionsIntroduction to regular expressions
Introduction to regular expressionsBen Brumfield
 
regular expressions (Regex)
regular expressions (Regex)regular expressions (Regex)
regular expressions (Regex)Rebaz Najeeb
 
context free language
context free languagecontext free language
context free languagekhush_boo31
 
function, storage class and array and strings
 function, storage class and array and strings function, storage class and array and strings
function, storage class and array and stringsRai University
 
Introduction to Regular Expressions
Introduction to Regular ExpressionsIntroduction to Regular Expressions
Introduction to Regular ExpressionsMatt Casto
 
A Quick Taste of C
A Quick Taste of CA Quick Taste of C
A Quick Taste of Cjeremyrand
 

What's hot (20)

strings in c language and its importance
strings in c language and its importancestrings in c language and its importance
strings in c language and its importance
 
Strings in C language
Strings in C languageStrings in C language
Strings in C language
 
Regex Presentation
Regex PresentationRegex Presentation
Regex Presentation
 
String functions
String functionsString functions
String functions
 
Context free grammar
Context free grammarContext free grammar
Context free grammar
 
C programming language character set keywords constants variables data types
C programming language character set keywords constants variables data typesC programming language character set keywords constants variables data types
C programming language character set keywords constants variables data types
 
L3 cfg
L3 cfgL3 cfg
L3 cfg
 
Regular Expression
Regular ExpressionRegular Expression
Regular Expression
 
Regular expressions
Regular expressionsRegular expressions
Regular expressions
 
Regular expressions
Regular expressionsRegular expressions
Regular expressions
 
Introduction to regular expressions
Introduction to regular expressionsIntroduction to regular expressions
Introduction to regular expressions
 
regular expressions (Regex)
regular expressions (Regex)regular expressions (Regex)
regular expressions (Regex)
 
Strings IN C
Strings IN CStrings IN C
Strings IN C
 
context free language
context free languagecontext free language
context free language
 
Recognition-of-tokens
Recognition-of-tokensRecognition-of-tokens
Recognition-of-tokens
 
Regular Expressions
Regular ExpressionsRegular Expressions
Regular Expressions
 
Strings
StringsStrings
Strings
 
function, storage class and array and strings
 function, storage class and array and strings function, storage class and array and strings
function, storage class and array and strings
 
Introduction to Regular Expressions
Introduction to Regular ExpressionsIntroduction to Regular Expressions
Introduction to Regular Expressions
 
A Quick Taste of C
A Quick Taste of CA Quick Taste of C
A Quick Taste of C
 

Similar to C - String ppt

Similar to C - String ppt (20)

string in C
string in Cstring in C
string in C
 
C string
C stringC string
C string
 
String in programming language in c or c++
 String in programming language  in c or c++  String in programming language  in c or c++
String in programming language in c or c++
 
Handling of character strings C programming
Handling of character strings C programmingHandling of character strings C programming
Handling of character strings C programming
 
String & its application
String & its applicationString & its application
String & its application
 
python_strings.pdf
python_strings.pdfpython_strings.pdf
python_strings.pdf
 
Lecture 05 2017
Lecture 05 2017Lecture 05 2017
Lecture 05 2017
 
Ch09
Ch09Ch09
Ch09
 
Strings in c mrs.sowmya jyothi
Strings in c mrs.sowmya jyothiStrings in c mrs.sowmya jyothi
Strings in c mrs.sowmya jyothi
 
fundamentals of c programming_String.pptx
fundamentals of c programming_String.pptxfundamentals of c programming_String.pptx
fundamentals of c programming_String.pptx
 
STRINGS IN C MRS.SOWMYA JYOTHI.pdf
STRINGS IN C MRS.SOWMYA JYOTHI.pdfSTRINGS IN C MRS.SOWMYA JYOTHI.pdf
STRINGS IN C MRS.SOWMYA JYOTHI.pdf
 
Strings in c++
Strings in c++Strings in c++
Strings in c++
 
introduction to strings in c programming
introduction to strings in c programmingintroduction to strings in c programming
introduction to strings in c programming
 
Operation on string presentation
Operation on string presentationOperation on string presentation
Operation on string presentation
 
Strings in c++
Strings in c++Strings in c++
Strings in c++
 
String in c in erode SENGUNTHAR engineering .pptx
String in c in erode SENGUNTHAR engineering .pptxString in c in erode SENGUNTHAR engineering .pptx
String in c in erode SENGUNTHAR engineering .pptx
 
String in c
String in cString in c
String in c
 
[ITP - Lecture 17] Strings in C/C++
[ITP - Lecture 17] Strings in C/C++[ITP - Lecture 17] Strings in C/C++
[ITP - Lecture 17] Strings in C/C++
 
UNIT 4 python.pptx
UNIT 4 python.pptxUNIT 4 python.pptx
UNIT 4 python.pptx
 
0-Slot21-22-Strings.pdf
0-Slot21-22-Strings.pdf0-Slot21-22-Strings.pdf
0-Slot21-22-Strings.pdf
 

More from Md Razib

Euler and Hamiltonian path and circuit
Euler and Hamiltonian path and circuitEuler and Hamiltonian path and circuit
Euler and Hamiltonian path and circuitMd Razib
 
Multiplexing (TDM)
Multiplexing (TDM)Multiplexing (TDM)
Multiplexing (TDM)Md Razib
 
Help Desk Software
Help Desk Software Help Desk Software
Help Desk Software Md Razib
 
Application of discrete Mathematic
Application of discrete  Mathematic Application of discrete  Mathematic
Application of discrete Mathematic Md Razib
 
Quality assurance ppt
Quality assurance ppt Quality assurance ppt
Quality assurance ppt Md Razib
 
Time and financial management ppt
Time and financial management pptTime and financial management ppt
Time and financial management pptMd Razib
 
About Electricity ppt
About Electricity ppt About Electricity ppt
About Electricity ppt Md Razib
 
Pitch deck presentation ( Medi Buy app)
Pitch deck presentation ( Medi Buy app)Pitch deck presentation ( Medi Buy app)
Pitch deck presentation ( Medi Buy app)Md Razib
 
Ged art of living career plan
Ged art of living career planGed art of living career plan
Ged art of living career planMd Razib
 

More from Md Razib (9)

Euler and Hamiltonian path and circuit
Euler and Hamiltonian path and circuitEuler and Hamiltonian path and circuit
Euler and Hamiltonian path and circuit
 
Multiplexing (TDM)
Multiplexing (TDM)Multiplexing (TDM)
Multiplexing (TDM)
 
Help Desk Software
Help Desk Software Help Desk Software
Help Desk Software
 
Application of discrete Mathematic
Application of discrete  Mathematic Application of discrete  Mathematic
Application of discrete Mathematic
 
Quality assurance ppt
Quality assurance ppt Quality assurance ppt
Quality assurance ppt
 
Time and financial management ppt
Time and financial management pptTime and financial management ppt
Time and financial management ppt
 
About Electricity ppt
About Electricity ppt About Electricity ppt
About Electricity ppt
 
Pitch deck presentation ( Medi Buy app)
Pitch deck presentation ( Medi Buy app)Pitch deck presentation ( Medi Buy app)
Pitch deck presentation ( Medi Buy app)
 
Ged art of living career plan
Ged art of living career planGed art of living career plan
Ged art of living career plan
 

Recently uploaded

Separation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesSeparation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesFatimaKhan178732
 
Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Celine George
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactPECB
 
URLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website AppURLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website AppCeline George
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxiammrhaywood
 
Hybridoma Technology ( Production , Purification , and Application )
Hybridoma Technology  ( Production , Purification , and Application  ) Hybridoma Technology  ( Production , Purification , and Application  )
Hybridoma Technology ( Production , Purification , and Application ) Sakshi Ghasle
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Sapana Sha
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxpboyjonauth
 
How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxmanuelaromero2013
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationnomboosow
 
Z Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphZ Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphThiyagu K
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introductionMaksud Ahmed
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Educationpboyjonauth
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdfSoniaTolstoy
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfciinovamais
 
Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3JemimahLaneBuaron
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)eniolaolutunde
 

Recently uploaded (20)

Separation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesSeparation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and Actinides
 
Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global Impact
 
URLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website AppURLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website App
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
 
Hybridoma Technology ( Production , Purification , and Application )
Hybridoma Technology  ( Production , Purification , and Application  ) Hybridoma Technology  ( Production , Purification , and Application  )
Hybridoma Technology ( Production , Purification , and Application )
 
Staff of Color (SOC) Retention Efforts DDSD
Staff of Color (SOC) Retention Efforts DDSDStaff of Color (SOC) Retention Efforts DDSD
Staff of Color (SOC) Retention Efforts DDSD
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptx
 
How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptx
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communication
 
Z Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphZ Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot Graph
 
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introduction
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Education
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
 
Mattingly "AI & Prompt Design: The Basics of Prompt Design"
Mattingly "AI & Prompt Design: The Basics of Prompt Design"Mattingly "AI & Prompt Design: The Basics of Prompt Design"
Mattingly "AI & Prompt Design: The Basics of Prompt Design"
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
 
Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)
 

C - String ppt

  • 2. C - String • strings are arrays of chars. String literals are words surrounded by double quotation marks. • The string in C programming language is actually a one-dimensional array of characters which is terminated by a null character '0'. Thus a null- terminated string contains the characters that comprise the string followed by a null. • A string can be declared as a character array or with a string pointer. • The following declaration and initialization create a string consisting of the word "Hello". To hold the null character at the end of the array, the size of the character array containing the string is one more than the number of characters in the word "Hello." "This is a static string" Or Or char *greeting = “Hello” ;
  • 3. C - String • Following is the memory presentation of above defined string in C/C++:  It's important to remember that there will be an extra character on the end on a string, literally a '0' character, just like there is always a period at the end of a sentence. Since this string terminator is unprintable, it is not counted as a letter, but it still takes up a space. Technically, in a fifty char array you could only hold 49 letters and one null character at the end to terminate the string.  Actually, you do not place the null character at the end of a string constant. The C compiler automatically places the '0' at the end of the string when it initializes the array.
  • 4. C - String • Let us try to print above mentioned string:  Note: %s is used to print a string.
  • 5. String pointer • String pointers are declared as a pointer to a char. • When there is a value assigned to the string pointer the NULL is put at the end automatically. • Take a look at this example:
  • 6. String pointer • It is not possible to read, with scanf(), a string with a string pointer. You have to use a character array and a pointer. See this example:
  • 7. Reading a line of text gets() and puts() are two string functions to take string input from user and display string respectively
  • 8. String related operations • Find the Frequency of Characters in a String • Find the Number of Vowels, Consonants, Digits and White space in a String • Reverse a String by Passing it to Function • Find the Length of a String • Concatenate Two Strings • Copy a String • Remove all Characters in a String except alphabet • Sort a string in alphabetic order • Sort Elements in Lexicographical Order (Dictionary Order) • Change Decimal to Hexadecimal Number • Convert Binary Number to Decimal
  • 9. Copy String Manually You can use the strcpy( ) function to copy the content of one string to another but, this program copies the content of one string to another manually without using strcpy( ) function.
  • 10. C library functions • C supports a wide range of functions that manipulate null-terminated strings: