SlideShare a Scribd company logo
1 of 21
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.
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
strcpy() 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
THANK YOU

More Related Content

What's hot (20)

Implementation Of String Functions In C
Implementation Of String Functions In CImplementation Of String Functions In C
Implementation Of String Functions In C
 
C++ presentation
C++ presentationC++ presentation
C++ presentation
 
Unit 2. Elements of C
Unit 2. Elements of CUnit 2. Elements of C
Unit 2. Elements of C
 
Strings in C
Strings in CStrings in C
Strings in C
 
C string
C stringC string
C string
 
Call by value
Call by valueCall by value
Call by value
 
Array in c language
Array in c languageArray in c language
Array in c language
 
Command line arguments
Command line argumentsCommand line arguments
Command line arguments
 
C programming - String
C programming - StringC programming - String
C programming - String
 
Functions in c language
Functions in c language Functions in c language
Functions in c language
 
Unit ii chapter 2 Decision making and Branching in C
Unit ii chapter 2 Decision making and Branching in CUnit ii chapter 2 Decision making and Branching in C
Unit ii chapter 2 Decision making and Branching in C
 
C functions
C functionsC functions
C functions
 
String functions in C
String functions in CString functions in C
String functions in C
 
Strings in c language
Strings in  c languageStrings in  c language
Strings in c language
 
Control statements
Control statementsControl statements
Control statements
 
Control Flow Statements
Control Flow Statements Control Flow Statements
Control Flow Statements
 
String C Programming
String C ProgrammingString C Programming
String C Programming
 
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
 
Arrays and Strings
Arrays and Strings Arrays and Strings
Arrays and Strings
 
Break and continue
Break and continueBreak and continue
Break and continue
 

Viewers also liked

Strings In OOP(Object oriented programming)
Strings In OOP(Object oriented programming)Strings In OOP(Object oriented programming)
Strings In OOP(Object oriented programming)Danial Virk
 
C programming string
C  programming stringC  programming string
C programming stringargusacademy
 
Handling Exceptions In C & C++ [Part B] Ver 2
Handling Exceptions In C & C++ [Part B] Ver 2Handling Exceptions In C & C++ [Part B] Ver 2
Handling Exceptions In C & C++ [Part B] Ver 2ppd1961
 
String Handling in c++
String Handling in c++String Handling in c++
String Handling in c++Fahim Adil
 
Handling Exceptions In C & C++[Part A]
Handling Exceptions In C & C++[Part A]Handling Exceptions In C & C++[Part A]
Handling Exceptions In C & C++[Part A]ppd1961
 
Exception Handling in C++
Exception Handling in C++Exception Handling in C++
Exception Handling in C++Deepak Tathe
 
Exception handling and templates
Exception handling and templatesException handling and templates
Exception handling and templatesfarhan amjad
 
Exception handling in c++ by manoj vasava
Exception handling in c++ by manoj vasavaException handling in c++ by manoj vasava
Exception handling in c++ by manoj vasavaManoj_vasava
 
Exception Handling
Exception HandlingException Handling
Exception HandlingReddhi Basu
 
Unit 2 Principles of Programming Languages
Unit 2 Principles of Programming LanguagesUnit 2 Principles of Programming Languages
Unit 2 Principles of Programming LanguagesVasavi College of Engg
 
Unit1 principle of programming language
Unit1 principle of programming languageUnit1 principle of programming language
Unit1 principle of programming languageVasavi College of Engg
 

Viewers also liked (20)

Strings
StringsStrings
Strings
 
Strings In OOP(Object oriented programming)
Strings In OOP(Object oriented programming)Strings In OOP(Object oriented programming)
Strings In OOP(Object oriented programming)
 
C programming string
C  programming stringC  programming string
C programming string
 
Handling Exceptions In C & C++ [Part B] Ver 2
Handling Exceptions In C & C++ [Part B] Ver 2Handling Exceptions In C & C++ [Part B] Ver 2
Handling Exceptions In C & C++ [Part B] Ver 2
 
05 c++-strings
05 c++-strings05 c++-strings
05 c++-strings
 
Strings
StringsStrings
Strings
 
String Handling in c++
String Handling in c++String Handling in c++
String Handling in c++
 
Handling Exceptions In C & C++[Part A]
Handling Exceptions In C & C++[Part A]Handling Exceptions In C & C++[Part A]
Handling Exceptions In C & C++[Part A]
 
Exception Handling in C++
Exception Handling in C++Exception Handling in C++
Exception Handling in C++
 
String c
String cString c
String c
 
Exception handling and templates
Exception handling and templatesException handling and templates
Exception handling and templates
 
Exception handling in c++ by manoj vasava
Exception handling in c++ by manoj vasavaException handling in c++ by manoj vasava
Exception handling in c++ by manoj vasava
 
String in c
String in cString in c
String in c
 
C vs c++
C vs c++C vs c++
C vs c++
 
Exception Handling
Exception HandlingException Handling
Exception Handling
 
Exception handling
Exception handlingException handling
Exception handling
 
Unit 2 Principles of Programming Languages
Unit 2 Principles of Programming LanguagesUnit 2 Principles of Programming Languages
Unit 2 Principles of Programming Languages
 
Ppt of c++ vs c#
Ppt of c++ vs c#Ppt of c++ vs c#
Ppt of c++ vs c#
 
C notes.pdf
C notes.pdfC notes.pdf
C notes.pdf
 
Unit1 principle of programming language
Unit1 principle of programming languageUnit1 principle of programming language
Unit1 principle of programming language
 

Similar to String in programming language in c or c++

Similar to String in programming language in c or c++ (20)

string in C
string in Cstring in C
string in 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 in programming language in c or c++
 
C - String ppt
C - String ppt C - String ppt
C - String ppt
 
Lecture 05 2017
Lecture 05 2017Lecture 05 2017
Lecture 05 2017
 
Strings in c++
Strings in c++Strings in c++
Strings in c++
 
String notes
String notesString notes
String notes
 
Strings in c mrs.sowmya jyothi
Strings in c mrs.sowmya jyothiStrings in c mrs.sowmya jyothi
Strings in c mrs.sowmya jyothi
 
Ch09
Ch09Ch09
Ch09
 
[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++
 
introduction to strings in c programming
introduction to strings in c programmingintroduction to strings in c programming
introduction to strings in c programming
 
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
 
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
 
Python regular expressions
Python regular expressionsPython regular expressions
Python regular expressions
 
python_strings.pdf
python_strings.pdfpython_strings.pdf
python_strings.pdf
 
Getting started with c++
Getting started with c++Getting started with c++
Getting started with c++
 
Getting started with c++
Getting started with c++Getting started with c++
Getting started with c++
 
3 character strings and formatted input output
3  character strings and formatted input output3  character strings and formatted input output
3 character strings and formatted input output
 
Lecture 2. mte 407
Lecture 2. mte 407Lecture 2. mte 407
Lecture 2. mte 407
 

More from Samsil Arefin

Transmission Control Protocol and User Datagram protocol
Transmission Control Protocol and User Datagram protocolTransmission Control Protocol and User Datagram protocol
Transmission Control Protocol and User Datagram protocolSamsil Arefin
 
Evolution Phylogenetic
Evolution PhylogeneticEvolution Phylogenetic
Evolution PhylogeneticSamsil Arefin
 
Evolution Phylogenetic
Evolution PhylogeneticEvolution Phylogenetic
Evolution PhylogeneticSamsil Arefin
 
Ego net facebook data analysis
Ego net facebook data analysisEgo net facebook data analysis
Ego net facebook data analysisSamsil Arefin
 
Augmented Reality (AR)
Augmented Reality (AR)Augmented Reality (AR)
Augmented Reality (AR)Samsil Arefin
 
Client server chat application
Client server chat applicationClient server chat application
Client server chat applicationSamsil Arefin
 
Strings in programming tutorial.
Strings  in programming tutorial.Strings  in programming tutorial.
Strings in programming tutorial.Samsil Arefin
 
Linked list searching deleting inserting
Linked list searching deleting insertingLinked list searching deleting inserting
Linked list searching deleting insertingSamsil Arefin
 
Program to sort the n names in an alphabetical order
Program to sort the n names in an alphabetical orderProgram to sort the n names in an alphabetical order
Program to sort the n names in an alphabetical orderSamsil Arefin
 
Linked list int_data_fdata
Linked list int_data_fdataLinked list int_data_fdata
Linked list int_data_fdataSamsil Arefin
 
Linked list Output tracing
Linked list Output tracingLinked list Output tracing
Linked list Output tracingSamsil Arefin
 
Fundamentals of-electric-circuit
Fundamentals of-electric-circuitFundamentals of-electric-circuit
Fundamentals of-electric-circuitSamsil Arefin
 
Data structure lecture 1
Data structure   lecture 1Data structure   lecture 1
Data structure lecture 1Samsil Arefin
 
Structure in programming in c or c++ or c# or java
Structure in programming  in c or c++ or c# or javaStructure in programming  in c or c++ or c# or java
Structure in programming in c or c++ or c# or javaSamsil Arefin
 

More from Samsil Arefin (20)

Transmission Control Protocol and User Datagram protocol
Transmission Control Protocol and User Datagram protocolTransmission Control Protocol and User Datagram protocol
Transmission Control Protocol and User Datagram protocol
 
Evolution Phylogenetic
Evolution PhylogeneticEvolution Phylogenetic
Evolution Phylogenetic
 
Evolution Phylogenetic
Evolution PhylogeneticEvolution Phylogenetic
Evolution Phylogenetic
 
Ego net facebook data analysis
Ego net facebook data analysisEgo net facebook data analysis
Ego net facebook data analysis
 
Augmented Reality (AR)
Augmented Reality (AR)Augmented Reality (AR)
Augmented Reality (AR)
 
Client server chat application
Client server chat applicationClient server chat application
Client server chat application
 
Strings in programming tutorial.
Strings  in programming tutorial.Strings  in programming tutorial.
Strings in programming tutorial.
 
Linked list searching deleting inserting
Linked list searching deleting insertingLinked list searching deleting inserting
Linked list searching deleting inserting
 
Number theory
Number theoryNumber theory
Number theory
 
Program to sort the n names in an alphabetical order
Program to sort the n names in an alphabetical orderProgram to sort the n names in an alphabetical order
Program to sort the n names in an alphabetical order
 
Linked list int_data_fdata
Linked list int_data_fdataLinked list int_data_fdata
Linked list int_data_fdata
 
Linked list Output tracing
Linked list Output tracingLinked list Output tracing
Linked list Output tracing
 
Stack
StackStack
Stack
 
Sorting
SortingSorting
Sorting
 
Fundamentals of-electric-circuit
Fundamentals of-electric-circuitFundamentals of-electric-circuit
Fundamentals of-electric-circuit
 
Cyber security
Cyber securityCyber security
Cyber security
 
C programming
C programmingC programming
C programming
 
Data structure lecture 1
Data structure   lecture 1Data structure   lecture 1
Data structure lecture 1
 
Structure and union
Structure and unionStructure and union
Structure and union
 
Structure in programming in c or c++ or c# or java
Structure in programming  in c or c++ or c# or javaStructure in programming  in c or c++ or c# or java
Structure in programming in c or c++ or c# or java
 

Recently uploaded

Concrete Mix Design - IS 10262-2019 - .pptx
Concrete Mix Design - IS 10262-2019 - .pptxConcrete Mix Design - IS 10262-2019 - .pptx
Concrete Mix Design - IS 10262-2019 - .pptxKartikeyaDwivedi3
 
Correctly Loading Incremental Data at Scale
Correctly Loading Incremental Data at ScaleCorrectly Loading Incremental Data at Scale
Correctly Loading Incremental Data at ScaleAlluxio, Inc.
 
CCS355 Neural Networks & Deep Learning Unit 1 PDF notes with Question bank .pdf
CCS355 Neural Networks & Deep Learning Unit 1 PDF notes with Question bank .pdfCCS355 Neural Networks & Deep Learning Unit 1 PDF notes with Question bank .pdf
CCS355 Neural Networks & Deep Learning Unit 1 PDF notes with Question bank .pdfAsst.prof M.Gokilavani
 
System Simulation and Modelling with types and Event Scheduling
System Simulation and Modelling with types and Event SchedulingSystem Simulation and Modelling with types and Event Scheduling
System Simulation and Modelling with types and Event SchedulingBootNeck1
 
An experimental study in using natural admixture as an alternative for chemic...
An experimental study in using natural admixture as an alternative for chemic...An experimental study in using natural admixture as an alternative for chemic...
An experimental study in using natural admixture as an alternative for chemic...Chandu841456
 
Why does (not) Kafka need fsync: Eliminating tail latency spikes caused by fsync
Why does (not) Kafka need fsync: Eliminating tail latency spikes caused by fsyncWhy does (not) Kafka need fsync: Eliminating tail latency spikes caused by fsync
Why does (not) Kafka need fsync: Eliminating tail latency spikes caused by fsyncssuser2ae721
 
Earthing details of Electrical Substation
Earthing details of Electrical SubstationEarthing details of Electrical Substation
Earthing details of Electrical Substationstephanwindworld
 
Virtual memory management in Operating System
Virtual memory management in Operating SystemVirtual memory management in Operating System
Virtual memory management in Operating SystemRashmi Bhat
 
Software and Systems Engineering Standards: Verification and Validation of Sy...
Software and Systems Engineering Standards: Verification and Validation of Sy...Software and Systems Engineering Standards: Verification and Validation of Sy...
Software and Systems Engineering Standards: Verification and Validation of Sy...VICTOR MAESTRE RAMIREZ
 
Energy Awareness training ppt for manufacturing process.pptx
Energy Awareness training ppt for manufacturing process.pptxEnergy Awareness training ppt for manufacturing process.pptx
Energy Awareness training ppt for manufacturing process.pptxsiddharthjain2303
 
Gurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort service
Gurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort serviceGurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort service
Gurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort servicejennyeacort
 
Input Output Management in Operating System
Input Output Management in Operating SystemInput Output Management in Operating System
Input Output Management in Operating SystemRashmi Bhat
 
Main Memory Management in Operating System
Main Memory Management in Operating SystemMain Memory Management in Operating System
Main Memory Management in Operating SystemRashmi Bhat
 
Call Girls Narol 7397865700 Independent Call Girls
Call Girls Narol 7397865700 Independent Call GirlsCall Girls Narol 7397865700 Independent Call Girls
Call Girls Narol 7397865700 Independent Call Girlsssuser7cb4ff
 
UNIT III ANALOG ELECTRONICS (BASIC ELECTRONICS)
UNIT III ANALOG ELECTRONICS (BASIC ELECTRONICS)UNIT III ANALOG ELECTRONICS (BASIC ELECTRONICS)
UNIT III ANALOG ELECTRONICS (BASIC ELECTRONICS)Dr SOUNDIRARAJ N
 
Risk Assessment For Installation of Drainage Pipes.pdf
Risk Assessment For Installation of Drainage Pipes.pdfRisk Assessment For Installation of Drainage Pipes.pdf
Risk Assessment For Installation of Drainage Pipes.pdfROCENODodongVILLACER
 
IVE Industry Focused Event - Defence Sector 2024
IVE Industry Focused Event - Defence Sector 2024IVE Industry Focused Event - Defence Sector 2024
IVE Industry Focused Event - Defence Sector 2024Mark Billinghurst
 
Steel Structures - Building technology.pptx
Steel Structures - Building technology.pptxSteel Structures - Building technology.pptx
Steel Structures - Building technology.pptxNikhil Raut
 
NO1 Certified Black Magic Specialist Expert Amil baba in Uae Dubai Abu Dhabi ...
NO1 Certified Black Magic Specialist Expert Amil baba in Uae Dubai Abu Dhabi ...NO1 Certified Black Magic Specialist Expert Amil baba in Uae Dubai Abu Dhabi ...
NO1 Certified Black Magic Specialist Expert Amil baba in Uae Dubai Abu Dhabi ...Amil Baba Dawood bangali
 
Work Experience-Dalton Park.pptxfvvvvvvv
Work Experience-Dalton Park.pptxfvvvvvvvWork Experience-Dalton Park.pptxfvvvvvvv
Work Experience-Dalton Park.pptxfvvvvvvvLewisJB
 

Recently uploaded (20)

Concrete Mix Design - IS 10262-2019 - .pptx
Concrete Mix Design - IS 10262-2019 - .pptxConcrete Mix Design - IS 10262-2019 - .pptx
Concrete Mix Design - IS 10262-2019 - .pptx
 
Correctly Loading Incremental Data at Scale
Correctly Loading Incremental Data at ScaleCorrectly Loading Incremental Data at Scale
Correctly Loading Incremental Data at Scale
 
CCS355 Neural Networks & Deep Learning Unit 1 PDF notes with Question bank .pdf
CCS355 Neural Networks & Deep Learning Unit 1 PDF notes with Question bank .pdfCCS355 Neural Networks & Deep Learning Unit 1 PDF notes with Question bank .pdf
CCS355 Neural Networks & Deep Learning Unit 1 PDF notes with Question bank .pdf
 
System Simulation and Modelling with types and Event Scheduling
System Simulation and Modelling with types and Event SchedulingSystem Simulation and Modelling with types and Event Scheduling
System Simulation and Modelling with types and Event Scheduling
 
An experimental study in using natural admixture as an alternative for chemic...
An experimental study in using natural admixture as an alternative for chemic...An experimental study in using natural admixture as an alternative for chemic...
An experimental study in using natural admixture as an alternative for chemic...
 
Why does (not) Kafka need fsync: Eliminating tail latency spikes caused by fsync
Why does (not) Kafka need fsync: Eliminating tail latency spikes caused by fsyncWhy does (not) Kafka need fsync: Eliminating tail latency spikes caused by fsync
Why does (not) Kafka need fsync: Eliminating tail latency spikes caused by fsync
 
Earthing details of Electrical Substation
Earthing details of Electrical SubstationEarthing details of Electrical Substation
Earthing details of Electrical Substation
 
Virtual memory management in Operating System
Virtual memory management in Operating SystemVirtual memory management in Operating System
Virtual memory management in Operating System
 
Software and Systems Engineering Standards: Verification and Validation of Sy...
Software and Systems Engineering Standards: Verification and Validation of Sy...Software and Systems Engineering Standards: Verification and Validation of Sy...
Software and Systems Engineering Standards: Verification and Validation of Sy...
 
Energy Awareness training ppt for manufacturing process.pptx
Energy Awareness training ppt for manufacturing process.pptxEnergy Awareness training ppt for manufacturing process.pptx
Energy Awareness training ppt for manufacturing process.pptx
 
Gurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort service
Gurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort serviceGurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort service
Gurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort service
 
Input Output Management in Operating System
Input Output Management in Operating SystemInput Output Management in Operating System
Input Output Management in Operating System
 
Main Memory Management in Operating System
Main Memory Management in Operating SystemMain Memory Management in Operating System
Main Memory Management in Operating System
 
Call Girls Narol 7397865700 Independent Call Girls
Call Girls Narol 7397865700 Independent Call GirlsCall Girls Narol 7397865700 Independent Call Girls
Call Girls Narol 7397865700 Independent Call Girls
 
UNIT III ANALOG ELECTRONICS (BASIC ELECTRONICS)
UNIT III ANALOG ELECTRONICS (BASIC ELECTRONICS)UNIT III ANALOG ELECTRONICS (BASIC ELECTRONICS)
UNIT III ANALOG ELECTRONICS (BASIC ELECTRONICS)
 
Risk Assessment For Installation of Drainage Pipes.pdf
Risk Assessment For Installation of Drainage Pipes.pdfRisk Assessment For Installation of Drainage Pipes.pdf
Risk Assessment For Installation of Drainage Pipes.pdf
 
IVE Industry Focused Event - Defence Sector 2024
IVE Industry Focused Event - Defence Sector 2024IVE Industry Focused Event - Defence Sector 2024
IVE Industry Focused Event - Defence Sector 2024
 
Steel Structures - Building technology.pptx
Steel Structures - Building technology.pptxSteel Structures - Building technology.pptx
Steel Structures - Building technology.pptx
 
NO1 Certified Black Magic Specialist Expert Amil baba in Uae Dubai Abu Dhabi ...
NO1 Certified Black Magic Specialist Expert Amil baba in Uae Dubai Abu Dhabi ...NO1 Certified Black Magic Specialist Expert Amil baba in Uae Dubai Abu Dhabi ...
NO1 Certified Black Magic Specialist Expert Amil baba in Uae Dubai Abu Dhabi ...
 
Work Experience-Dalton Park.pptxfvvvvvvv
Work Experience-Dalton Park.pptxfvvvvvvvWork Experience-Dalton Park.pptxfvvvvvvv
Work Experience-Dalton Park.pptxfvvvvvvv
 

String in programming language in c or c++

  • 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. READING A LINE OF TEXT gets() and puts() are two string functions to take string input from user and display string respectively
  • 6. 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
  • 7. FIND THE FREQUENCY OF CHARACTERS
  • 8. 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.
  • 9. FIND NUMBER OF VOWELS, CONSONANTS, DIGITS AND WHITE SPACE CHARACTER Output
  • 10. REVERSE STRING To solve this problem, two standard library functions strlen() and strcpy() are used to calculate length and to copy string respectively.
  • 11. 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.
  • 12. CONCATENATE TWO STRINGS MANUALLY You can concatenate two strings using standard library function strcat( ) , this program concatenates two strings manually without using strcat( ) function.
  • 13. 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.
  • 14. 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.
  • 15. 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.
  • 16. 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.
  • 17. C LIBRARY FUNCTIONS  C supports a wide range of functions that manipulate null-terminated strings:
  • 18. Following example makes use of few of the above- mentioned functions:
  • 19. 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.
  • 20. 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