SlideShare a Scribd company logo
1 of 22
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” ;
 Following is the memory presentation of above defined string in
C/C++:
C - STRING
 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.
 Let us try to print above mentioned string:
C - 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:
 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:
STRING POINTER
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
FIND THE FREQUENCY OF CHARACTERS
C PROGRAM TO FIND FREQUENCY OF CHARACTERS IN A STRING
This program computes
frequency of characters in a
string i.e. which character is
present how many times in a
string.
For example in the string
"code" each of the character
'c', 'o', 'd', and 'e' has
occurred one time.
Only lower case alphabets
are considered, other
characters (uppercase and
special characters) are
ignored. You can easily
modify this program to
handle uppercase and
special symbols.
FIND NUMBER OF VOWELS, CONSONANTS, DIGITS AND WHITE SPACE
CHARACTER
Output
REVERSE STRING
To solve this problem,
two standard library
functions strlen() and st
rcpy() are used to
calculate length and to
copy string
respectively.
CALCULATED LENGTH OF A STRING WITHOUT USING STRLEN()
FUNCTION
You can use standard library function strlen( ) to find the length of a string but,
this program computes the length of a string manually without using strlen( )
funtion.
CONCATENATE TWO STRINGS MANUALLY
You can concatenate two strings using standard library function strcat( ) , this
program concatenates two strings manually without using strcat( ) function.
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.
REMOVE CHARACTERS IN STRING EXCEPT ALPHABETS
This program
takes a string
from user and for
loop executed
until all characters
of string is
checked. If any
character inside a
string is not a
alphabet, all
characters after it
including null
character is
shifted by 1
position
backwards.
SORT A STRING IN ALPHABETIC
ORDER
C program to sort a string in alphabetic order:
For example if user will enter a string
"programming" then output will be
"aggimmnoprr" or output string will contain
characters in alphabetical order.
SORT ELEMENTS IN LEXICOGRAPHICAL ORDER
(DICTIONARY ORDER)
This program takes 10 words
from user and sorts elements in
lexicographical order. To perform
this task, two dimensional string
is used.
C LIBRARY FUNCTIONS
 C supports a wide range of functions that manipulate null-
terminated strings:
Following example makes use of few of the above-mentioned functions:
STRCAT( ) FUNCTION
 strcat( ) function concatenates two given strings. It
concatenates source string at the end of destination string.
 Syntax for strcat( ) function is given below.
 char * strcat ( char * destination, const char * source );
 Example :
 strcat ( str2, str1 ); - str1 is concatenated at the end of str2.
strcat ( str1, str2 ); - str2 is concatenated at the end of str1.
 As you know, each string in C is ended up with null character
(‘0′).
 In strcat( ) operation, null character of destination string is
overwritten by source string’s first character and null character
is added at the end of new destination string which is created
after strcat( ) operation.
EXAMPLE PROGRAM FOR STRCAT( )
 In this program, two strings “is fun” and “C tutorial”
are concatenated using strcat( ) function and result is displayed as
“C tutorial is fun”.
Output:
Source string = is fun
Target string = C tutorial
Target string after strcat( ) = C tutorial is fun

More Related Content

What's hot

Structures in c language
Structures in c languageStructures in c language
Structures in c languagetanmaymodi4
 
String In C Language
String In C Language String In C Language
String In C Language Simplilearn
 
Constants in C Programming
Constants in C ProgrammingConstants in C Programming
Constants in C Programmingprogramming9
 
Strings in C language
Strings in C languageStrings in C language
Strings in C languageP M Patil
 
Presentation on c structures
Presentation on c   structures Presentation on c   structures
Presentation on c structures topu93
 
C-Programming C LIBRARIES AND USER DEFINED LIBRARIES.pptx
C-Programming  C LIBRARIES AND USER DEFINED LIBRARIES.pptxC-Programming  C LIBRARIES AND USER DEFINED LIBRARIES.pptx
C-Programming C LIBRARIES AND USER DEFINED LIBRARIES.pptxSKUP1
 
Branching statements
Branching statementsBranching statements
Branching statementsArunMK17
 
C decision making and looping.
C decision making and looping.C decision making and looping.
C decision making and looping.Haard Shah
 
Functions in c language
Functions in c language Functions in c language
Functions in c language tanmaymodi4
 
Data types in C language
Data types in C languageData types in C language
Data types in C languagekashyap399
 

What's hot (20)

Structures in c language
Structures in c languageStructures in c language
Structures in c language
 
Strings in C
Strings in CStrings in C
Strings in C
 
String In C Language
String In C Language String In C Language
String In C Language
 
Strings and pointers
Strings and pointersStrings and pointers
Strings and pointers
 
String C Programming
String C ProgrammingString C Programming
String C Programming
 
Constants in C Programming
Constants in C ProgrammingConstants in C Programming
Constants in C Programming
 
Structure & union
Structure & unionStructure & union
Structure & union
 
Strings in C language
Strings in C languageStrings in C language
Strings in C language
 
Functions in c++
Functions in c++Functions in c++
Functions in c++
 
Functions in c
Functions in cFunctions in c
Functions in c
 
Presentation on c structures
Presentation on c   structures Presentation on c   structures
Presentation on c structures
 
C tokens
C tokensC tokens
C tokens
 
C-Programming C LIBRARIES AND USER DEFINED LIBRARIES.pptx
C-Programming  C LIBRARIES AND USER DEFINED LIBRARIES.pptxC-Programming  C LIBRARIES AND USER DEFINED LIBRARIES.pptx
C-Programming C LIBRARIES AND USER DEFINED LIBRARIES.pptx
 
Structure in C
Structure in CStructure in C
Structure in C
 
Branching statements
Branching statementsBranching statements
Branching statements
 
C decision making and looping.
C decision making and looping.C decision making and looping.
C decision making and looping.
 
Functions in c language
Functions in c language Functions in c language
Functions in c language
 
C Token’s
C Token’sC Token’s
C Token’s
 
Data types in C language
Data types in C languageData types in C language
Data types in C language
 
2D Array
2D Array 2D Array
2D Array
 

Viewers also liked (20)

String in c
String in cString in c
String in c
 
C programming string
C  programming stringC  programming string
C programming string
 
Strings
StringsStrings
Strings
 
Strings
StringsStrings
Strings
 
Implementation of c string functions
Implementation of c string functionsImplementation of c string functions
Implementation of c string functions
 
Computer Programming- Lecture 5
Computer Programming- Lecture 5 Computer Programming- Lecture 5
Computer Programming- Lecture 5
 
Structure in c
Structure in cStructure in c
Structure in c
 
Array in c language
Array in c languageArray in c language
Array in c language
 
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++
 
Structure in C
Structure in CStructure in C
Structure in C
 
structure and union
structure and unionstructure and union
structure and union
 
Arrays
ArraysArrays
Arrays
 
String functions
String functionsString functions
String functions
 
String functions and operations
String functions and operations String functions and operations
String functions and operations
 
Web Project Presentation - JoinPakForces
Web Project Presentation - JoinPakForcesWeb Project Presentation - JoinPakForces
Web Project Presentation - JoinPakForces
 
C++ Preprocessor Directives
C++ Preprocessor DirectivesC++ Preprocessor Directives
C++ Preprocessor Directives
 
Structures,pointers and strings in c Programming
Structures,pointers and strings in c ProgrammingStructures,pointers and strings in c Programming
Structures,pointers and strings in c Programming
 
String operation
String operationString operation
String operation
 
C tutorial
C tutorialC tutorial
C tutorial
 
C programming session 01
C programming session 01C programming session 01
C programming session 01
 

Similar to C string

Similar to C string (20)

string in C
string in Cstring in C
string in C
 
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 mrs.sowmya jyothi
Strings in c mrs.sowmya jyothiStrings in c mrs.sowmya jyothi
Strings in c mrs.sowmya jyothi
 
introduction to strings in c programming
introduction to strings in c programmingintroduction to strings in c programming
introduction to strings in c programming
 
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++
 
String notes
String notesString notes
String notes
 
Lecture 05 2017
Lecture 05 2017Lecture 05 2017
Lecture 05 2017
 
Strings in c++
Strings in c++Strings in c++
Strings 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++
 
C - String ppt
C - String ppt C - String ppt
C - String ppt
 
Week6_P_String.pptx
Week6_P_String.pptxWeek6_P_String.pptx
Week6_P_String.pptx
 
Handling of character strings C programming
Handling of character strings C programmingHandling of character strings C programming
Handling of character strings C programming
 
Character Arrays and strings in c language
Character Arrays and strings in c languageCharacter Arrays and strings in c language
Character Arrays and strings in c language
 
Strings
StringsStrings
Strings
 
String & its application
String & its applicationString & its application
String & its application
 
0-Slot21-22-Strings.pdf
0-Slot21-22-Strings.pdf0-Slot21-22-Strings.pdf
0-Slot21-22-Strings.pdf
 
Python data handling
Python data handlingPython data handling
Python data handling
 
Lecture 2. mte 407
Lecture 2. mte 407Lecture 2. mte 407
Lecture 2. mte 407
 
Strings in c
Strings in cStrings in c
Strings in c
 
14 strings
14 strings14 strings
14 strings
 

More from University of Potsdam (20)

Computer fundamentals 01
Computer fundamentals 01Computer fundamentals 01
Computer fundamentals 01
 
Workshop on android apps development
Workshop on android apps developmentWorkshop on android apps development
Workshop on android apps development
 
Transparency and concurrency
Transparency and concurrencyTransparency and concurrency
Transparency and concurrency
 
Database System Architecture
Database System ArchitectureDatabase System Architecture
Database System Architecture
 
Functional dependency and normalization
Functional dependency and normalizationFunctional dependency and normalization
Functional dependency and normalization
 
indexing and hashing
indexing and hashingindexing and hashing
indexing and hashing
 
data recovery-raid
data recovery-raiddata recovery-raid
data recovery-raid
 
Query processing
Query processingQuery processing
Query processing
 
Machine Learning for Data Mining
Machine Learning for Data MiningMachine Learning for Data Mining
Machine Learning for Data Mining
 
Tree, function and graph
Tree, function and graphTree, function and graph
Tree, function and graph
 
Sonet
SonetSonet
Sonet
 
Sets in discrete mathematics
Sets in discrete mathematicsSets in discrete mathematics
Sets in discrete mathematics
 
Set in discrete mathematics
Set in discrete mathematicsSet in discrete mathematics
Set in discrete mathematics
 
Series parallel ac rlc networks
Series parallel ac rlc networksSeries parallel ac rlc networks
Series parallel ac rlc networks
 
Series parallel ac networks
Series parallel ac networksSeries parallel ac networks
Series parallel ac networks
 
Relations
RelationsRelations
Relations
 
Relations
RelationsRelations
Relations
 
Propositional logic
Propositional logicPropositional logic
Propositional logic
 
Propositional logic
Propositional logicPropositional logic
Propositional logic
 
Prim algorithm
Prim algorithmPrim algorithm
Prim algorithm
 

Recently uploaded

MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptxMULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptxAnupkumar Sharma
 
Field Attribute Index Feature in Odoo 17
Field Attribute Index Feature in Odoo 17Field Attribute Index Feature in Odoo 17
Field Attribute Index Feature in Odoo 17Celine George
 
Inclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdf
Inclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdfInclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdf
Inclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdfTechSoup
 
Keynote by Prof. Wurzer at Nordex about IP-design
Keynote by Prof. Wurzer at Nordex about IP-designKeynote by Prof. Wurzer at Nordex about IP-design
Keynote by Prof. Wurzer at Nordex about IP-designMIPLM
 
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptx
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptxINTRODUCTION TO CATHOLIC CHRISTOLOGY.pptx
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptxHumphrey A Beña
 
Earth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatEarth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatYousafMalik24
 
Proudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxProudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxthorishapillay1
 
Grade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdf
Grade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdfGrade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdf
Grade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdfJemuel Francisco
 
What is Model Inheritance in Odoo 17 ERP
What is Model Inheritance in Odoo 17 ERPWhat is Model Inheritance in Odoo 17 ERP
What is Model Inheritance in Odoo 17 ERPCeline George
 
USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...
USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...
USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...Postal Advocate Inc.
 
AUDIENCE THEORY -CULTIVATION THEORY - GERBNER.pptx
AUDIENCE THEORY -CULTIVATION THEORY -  GERBNER.pptxAUDIENCE THEORY -CULTIVATION THEORY -  GERBNER.pptx
AUDIENCE THEORY -CULTIVATION THEORY - GERBNER.pptxiammrhaywood
 
Difference Between Search & Browse Methods in Odoo 17
Difference Between Search & Browse Methods in Odoo 17Difference Between Search & Browse Methods in Odoo 17
Difference Between Search & Browse Methods in Odoo 17Celine George
 
4.18.24 Movement Legacies, Reflection, and Review.pptx
4.18.24 Movement Legacies, Reflection, and Review.pptx4.18.24 Movement Legacies, Reflection, and Review.pptx
4.18.24 Movement Legacies, Reflection, and Review.pptxmary850239
 
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...JhezDiaz1
 
Global Lehigh Strategic Initiatives (without descriptions)
Global Lehigh Strategic Initiatives (without descriptions)Global Lehigh Strategic Initiatives (without descriptions)
Global Lehigh Strategic Initiatives (without descriptions)cama23
 
GRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTS
GRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTSGRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTS
GRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTSJoshuaGantuangco2
 

Recently uploaded (20)

MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptxMULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
 
Field Attribute Index Feature in Odoo 17
Field Attribute Index Feature in Odoo 17Field Attribute Index Feature in Odoo 17
Field Attribute Index Feature in Odoo 17
 
Inclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdf
Inclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdfInclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdf
Inclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdf
 
Keynote by Prof. Wurzer at Nordex about IP-design
Keynote by Prof. Wurzer at Nordex about IP-designKeynote by Prof. Wurzer at Nordex about IP-design
Keynote by Prof. Wurzer at Nordex about IP-design
 
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptx
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptxINTRODUCTION TO CATHOLIC CHRISTOLOGY.pptx
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptx
 
Earth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatEarth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice great
 
Proudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxProudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptx
 
Grade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdf
Grade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdfGrade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdf
Grade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdf
 
YOUVE_GOT_EMAIL_PRELIMS_EL_DORADO_2024.pptx
YOUVE_GOT_EMAIL_PRELIMS_EL_DORADO_2024.pptxYOUVE_GOT_EMAIL_PRELIMS_EL_DORADO_2024.pptx
YOUVE_GOT_EMAIL_PRELIMS_EL_DORADO_2024.pptx
 
What is Model Inheritance in Odoo 17 ERP
What is Model Inheritance in Odoo 17 ERPWhat is Model Inheritance in Odoo 17 ERP
What is Model Inheritance in Odoo 17 ERP
 
USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...
USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...
USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...
 
AUDIENCE THEORY -CULTIVATION THEORY - GERBNER.pptx
AUDIENCE THEORY -CULTIVATION THEORY -  GERBNER.pptxAUDIENCE THEORY -CULTIVATION THEORY -  GERBNER.pptx
AUDIENCE THEORY -CULTIVATION THEORY - GERBNER.pptx
 
Difference Between Search & Browse Methods in Odoo 17
Difference Between Search & Browse Methods in Odoo 17Difference Between Search & Browse Methods in Odoo 17
Difference Between Search & Browse Methods in Odoo 17
 
4.18.24 Movement Legacies, Reflection, and Review.pptx
4.18.24 Movement Legacies, Reflection, and Review.pptx4.18.24 Movement Legacies, Reflection, and Review.pptx
4.18.24 Movement Legacies, Reflection, and Review.pptx
 
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
 
YOUVE GOT EMAIL_FINALS_EL_DORADO_2024.pptx
YOUVE GOT EMAIL_FINALS_EL_DORADO_2024.pptxYOUVE GOT EMAIL_FINALS_EL_DORADO_2024.pptx
YOUVE GOT EMAIL_FINALS_EL_DORADO_2024.pptx
 
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
 
Global Lehigh Strategic Initiatives (without descriptions)
Global Lehigh Strategic Initiatives (without descriptions)Global Lehigh Strategic Initiatives (without descriptions)
Global Lehigh Strategic Initiatives (without descriptions)
 
LEFT_ON_C'N_ PRELIMS_EL_DORADO_2024.pptx
LEFT_ON_C'N_ PRELIMS_EL_DORADO_2024.pptxLEFT_ON_C'N_ PRELIMS_EL_DORADO_2024.pptx
LEFT_ON_C'N_ PRELIMS_EL_DORADO_2024.pptx
 
GRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTS
GRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTSGRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTS
GRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTS
 

C string

  • 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.  Following is the memory presentation of above defined string in C/C++: C - STRING  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.  Let us try to print above mentioned string: C - 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.  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: STRING POINTER
  • 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. FIND THE FREQUENCY OF CHARACTERS
  • 10. C PROGRAM TO FIND FREQUENCY OF CHARACTERS IN A STRING This program computes frequency of characters in a string i.e. which character is present how many times in a string. For example in the string "code" each of the character 'c', 'o', 'd', and 'e' has occurred one time. Only lower case alphabets are considered, other characters (uppercase and special characters) are ignored. You can easily modify this program to handle uppercase and special symbols.
  • 11. FIND NUMBER OF VOWELS, CONSONANTS, DIGITS AND WHITE SPACE CHARACTER Output
  • 12. REVERSE STRING To solve this problem, two standard library functions strlen() and st rcpy() are used to calculate length and to copy string respectively.
  • 13. CALCULATED LENGTH OF A STRING WITHOUT USING STRLEN() FUNCTION You can use standard library function strlen( ) to find the length of a string but, this program computes the length of a string manually without using strlen( ) funtion.
  • 14. CONCATENATE TWO STRINGS MANUALLY You can concatenate two strings using standard library function strcat( ) , this program concatenates two strings manually without using strcat( ) function.
  • 15. 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.
  • 16. REMOVE CHARACTERS IN STRING EXCEPT ALPHABETS This program takes a string from user and for loop executed until all characters of string is checked. If any character inside a string is not a alphabet, all characters after it including null character is shifted by 1 position backwards.
  • 17. SORT A STRING IN ALPHABETIC ORDER C program to sort a string in alphabetic order: For example if user will enter a string "programming" then output will be "aggimmnoprr" or output string will contain characters in alphabetical order.
  • 18. SORT ELEMENTS IN LEXICOGRAPHICAL ORDER (DICTIONARY ORDER) This program takes 10 words from user and sorts elements in lexicographical order. To perform this task, two dimensional string is used.
  • 19. C LIBRARY FUNCTIONS  C supports a wide range of functions that manipulate null- terminated strings:
  • 20. Following example makes use of few of the above-mentioned functions:
  • 21. STRCAT( ) FUNCTION  strcat( ) function concatenates two given strings. It concatenates source string at the end of destination string.  Syntax for strcat( ) function is given below.  char * strcat ( char * destination, const char * source );  Example :  strcat ( str2, str1 ); - str1 is concatenated at the end of str2. strcat ( str1, str2 ); - str2 is concatenated at the end of str1.  As you know, each string in C is ended up with null character (‘0′).  In strcat( ) operation, null character of destination string is overwritten by source string’s first character and null character is added at the end of new destination string which is created after strcat( ) operation.
  • 22. EXAMPLE PROGRAM FOR STRCAT( )  In this program, two strings “is fun” and “C tutorial” are concatenated using strcat( ) function and result is displayed as “C tutorial is fun”. Output: Source string = is fun Target string = C tutorial Target string after strcat( ) = C tutorial is fun