SlideShare a Scribd company logo
1 of 23
C STRING
By:Er. Anupam Sharma
Assistant Professor
anupamcgctc@gmail.com
C - STRING
 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."
 strings are arrays of chars. String literals are words surrounded
by double quotation marks.
"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 WITHOUTUSING 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
Target string
= is fun
= C tutorial
Target string after strcat( ) = C tutorial is fun
Thanks for your time and attention!

More Related Content

What's hot (20)

Strings in c
Strings in cStrings in c
Strings in c
 
String in c
String in cString in c
String in c
 
Handling of character strings C programming
Handling of character strings C programmingHandling of character strings C programming
Handling of character strings C programming
 
Strings in c++
Strings in c++Strings in c++
Strings in c++
 
String c
String cString c
String c
 
File Pointers
File PointersFile Pointers
File Pointers
 
Types of function call
Types of function callTypes of function call
Types of function call
 
Dynamic memory allocation in c
Dynamic memory allocation in cDynamic memory allocation in c
Dynamic memory allocation in c
 
File handling in c
File handling in cFile handling in c
File handling in c
 
Two dimensional array
Two dimensional arrayTwo dimensional array
Two dimensional array
 
Strings
StringsStrings
Strings
 
Enums in c
Enums in cEnums in c
Enums in c
 
String functions in C
String functions in CString functions in C
String functions in C
 
MANAGING INPUT AND OUTPUT OPERATIONS IN C MRS.SOWMYA JYOTHI.pdf
MANAGING INPUT AND OUTPUT OPERATIONS IN C    MRS.SOWMYA JYOTHI.pdfMANAGING INPUT AND OUTPUT OPERATIONS IN C    MRS.SOWMYA JYOTHI.pdf
MANAGING INPUT AND OUTPUT OPERATIONS IN C MRS.SOWMYA JYOTHI.pdf
 
Pointer in c
Pointer in cPointer in c
Pointer in c
 
String in c programming
String in c programmingString in c programming
String in c programming
 
Arrays in c
Arrays in cArrays in c
Arrays in c
 
Function in c
Function in cFunction in c
Function in c
 
Chapter 4 strings
Chapter 4 stringsChapter 4 strings
Chapter 4 strings
 
Nesting of if else statement & Else If Ladder
Nesting of if else statement & Else If Ladder Nesting of if else statement & Else If Ladder
Nesting of if else statement & Else If Ladder
 

Similar to 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++ Samsil Arefin
 
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.pdfSowmyaJyothi3
 
Strings in c mrs.sowmya jyothi
Strings in c mrs.sowmya jyothiStrings in c mrs.sowmya jyothi
Strings in c mrs.sowmya jyothiSowmya Jyothi
 
introduction to strings in c programming
introduction to strings in c programmingintroduction to strings in c programming
introduction to strings in c programmingmikeymanjiro2090
 
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++Azeemaj101
 
C - String ppt
C - String ppt C - String ppt
C - String ppt Md Razib
 
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 languagemallikavin
 
String & its application
String & its applicationString & its application
String & its applicationTech_MX
 
0-Slot21-22-Strings.pdf
0-Slot21-22-Strings.pdf0-Slot21-22-Strings.pdf
0-Slot21-22-Strings.pdfssusere19c741
 
Operation on string presentation
Operation on string presentationOperation on string presentation
Operation on string presentationAliul Kadir Akib
 

Similar to string in C (20)

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++
 
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 notes
String notesString notes
String notes
 
Lecture 05 2017
Lecture 05 2017Lecture 05 2017
Lecture 05 2017
 
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++
 
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
 
Strings
StringsStrings
Strings
 
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 and pointers
Strings and pointersStrings and pointers
Strings and pointers
 
Week6_P_String.pptx
Week6_P_String.pptxWeek6_P_String.pptx
Week6_P_String.pptx
 
String & its application
String & its applicationString & its application
String & its application
 
Python data handling
Python data handlingPython data handling
Python data handling
 
14 strings
14 strings14 strings
14 strings
 
0-Slot21-22-Strings.pdf
0-Slot21-22-Strings.pdf0-Slot21-22-Strings.pdf
0-Slot21-22-Strings.pdf
 
Operation on string presentation
Operation on string presentationOperation on string presentation
Operation on string presentation
 
Lecture 2. mte 407
Lecture 2. mte 407Lecture 2. mte 407
Lecture 2. mte 407
 

More from CGC Technical campus,Mohali

Data processing and Report writing in Research(Section E)
Data processing and Report writing in Research(Section E)Data processing and Report writing in Research(Section E)
Data processing and Report writing in Research(Section E)CGC Technical campus,Mohali
 
data analysis and report wring in research (Section d)
data analysis and report wring  in research (Section d)data analysis and report wring  in research (Section d)
data analysis and report wring in research (Section d)CGC Technical campus,Mohali
 
Section C(Analytical and descriptive surveys... )
Section C(Analytical and descriptive surveys... )Section C(Analytical and descriptive surveys... )
Section C(Analytical and descriptive surveys... )CGC Technical campus,Mohali
 

More from CGC Technical campus,Mohali (20)

Gender Issues CS.pptx
Gender Issues CS.pptxGender Issues CS.pptx
Gender Issues CS.pptx
 
Intellectual Property Rights.pptx
Intellectual Property Rights.pptxIntellectual Property Rights.pptx
Intellectual Property Rights.pptx
 
Cyber Safety ppt.pptx
Cyber Safety ppt.pptxCyber Safety ppt.pptx
Cyber Safety ppt.pptx
 
Python Modules .pptx
Python Modules .pptxPython Modules .pptx
Python Modules .pptx
 
Dynamic allocation
Dynamic allocationDynamic allocation
Dynamic allocation
 
Arrays in c
Arrays in cArrays in c
Arrays in c
 
Control statments in c
Control statments in cControl statments in c
Control statments in c
 
Operators in c by anupam
Operators in c by anupamOperators in c by anupam
Operators in c by anupam
 
Datatypes in c
Datatypes in cDatatypes in c
Datatypes in c
 
Fundamentals of-computer
Fundamentals of-computerFundamentals of-computer
Fundamentals of-computer
 
Searching
Searching Searching
Searching
 
File handling-c
File handling-cFile handling-c
File handling-c
 
Structure in C language
Structure in C languageStructure in C language
Structure in C language
 
Intro
IntroIntro
Intro
 
Function in c program
Function in c programFunction in c program
Function in c program
 
Function in c
Function in cFunction in c
Function in c
 
C arrays
C arraysC arrays
C arrays
 
Data processing and Report writing in Research(Section E)
Data processing and Report writing in Research(Section E)Data processing and Report writing in Research(Section E)
Data processing and Report writing in Research(Section E)
 
data analysis and report wring in research (Section d)
data analysis and report wring  in research (Section d)data analysis and report wring  in research (Section d)
data analysis and report wring in research (Section d)
 
Section C(Analytical and descriptive surveys... )
Section C(Analytical and descriptive surveys... )Section C(Analytical and descriptive surveys... )
Section C(Analytical and descriptive surveys... )
 

Recently uploaded

(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...ranjana rawat
 
UNIT-III FMM. DIMENSIONAL ANALYSIS
UNIT-III FMM.        DIMENSIONAL ANALYSISUNIT-III FMM.        DIMENSIONAL ANALYSIS
UNIT-III FMM. DIMENSIONAL ANALYSISrknatarajan
 
HARMONY IN THE NATURE AND EXISTENCE - Unit-IV
HARMONY IN THE NATURE AND EXISTENCE - Unit-IVHARMONY IN THE NATURE AND EXISTENCE - Unit-IV
HARMONY IN THE NATURE AND EXISTENCE - Unit-IVRajaP95
 
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur EscortsHigh Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur EscortsCall Girls in Nagpur High Profile
 
Porous Ceramics seminar and technical writing
Porous Ceramics seminar and technical writingPorous Ceramics seminar and technical writing
Porous Ceramics seminar and technical writingrakeshbaidya232001
 
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...ranjana rawat
 
(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...ranjana rawat
 
247267395-1-Symmetric-and-distributed-shared-memory-architectures-ppt (1).ppt
247267395-1-Symmetric-and-distributed-shared-memory-architectures-ppt (1).ppt247267395-1-Symmetric-and-distributed-shared-memory-architectures-ppt (1).ppt
247267395-1-Symmetric-and-distributed-shared-memory-architectures-ppt (1).pptssuser5c9d4b1
 
Introduction to Multiple Access Protocol.pptx
Introduction to Multiple Access Protocol.pptxIntroduction to Multiple Access Protocol.pptx
Introduction to Multiple Access Protocol.pptxupamatechverse
 
Introduction and different types of Ethernet.pptx
Introduction and different types of Ethernet.pptxIntroduction and different types of Ethernet.pptx
Introduction and different types of Ethernet.pptxupamatechverse
 
(RIA) Call Girls Bhosari ( 7001035870 ) HI-Fi Pune Escorts Service
(RIA) Call Girls Bhosari ( 7001035870 ) HI-Fi Pune Escorts Service(RIA) Call Girls Bhosari ( 7001035870 ) HI-Fi Pune Escorts Service
(RIA) Call Girls Bhosari ( 7001035870 ) HI-Fi Pune Escorts Serviceranjana rawat
 
UNIT - IV - Air Compressors and its Performance
UNIT - IV - Air Compressors and its PerformanceUNIT - IV - Air Compressors and its Performance
UNIT - IV - Air Compressors and its Performancesivaprakash250
 
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur Escorts
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur EscortsCall Girls in Nagpur Suman Call 7001035870 Meet With Nagpur Escorts
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur EscortsCall Girls in Nagpur High Profile
 
(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...
(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...
(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...ranjana rawat
 
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur EscortsHigh Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escortsranjana rawat
 
VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130
VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130
VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130Suhani Kapoor
 
Microscopic Analysis of Ceramic Materials.pptx
Microscopic Analysis of Ceramic Materials.pptxMicroscopic Analysis of Ceramic Materials.pptx
Microscopic Analysis of Ceramic Materials.pptxpurnimasatapathy1234
 
Coefficient of Thermal Expansion and their Importance.pptx
Coefficient of Thermal Expansion and their Importance.pptxCoefficient of Thermal Expansion and their Importance.pptx
Coefficient of Thermal Expansion and their Importance.pptxAsutosh Ranjan
 
Extrusion Processes and Their Limitations
Extrusion Processes and Their LimitationsExtrusion Processes and Their Limitations
Extrusion Processes and Their Limitations120cr0395
 
SPICE PARK APR2024 ( 6,793 SPICE Models )
SPICE PARK APR2024 ( 6,793 SPICE Models )SPICE PARK APR2024 ( 6,793 SPICE Models )
SPICE PARK APR2024 ( 6,793 SPICE Models )Tsuyoshi Horigome
 

Recently uploaded (20)

(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
 
UNIT-III FMM. DIMENSIONAL ANALYSIS
UNIT-III FMM.        DIMENSIONAL ANALYSISUNIT-III FMM.        DIMENSIONAL ANALYSIS
UNIT-III FMM. DIMENSIONAL ANALYSIS
 
HARMONY IN THE NATURE AND EXISTENCE - Unit-IV
HARMONY IN THE NATURE AND EXISTENCE - Unit-IVHARMONY IN THE NATURE AND EXISTENCE - Unit-IV
HARMONY IN THE NATURE AND EXISTENCE - Unit-IV
 
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur EscortsHigh Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
 
Porous Ceramics seminar and technical writing
Porous Ceramics seminar and technical writingPorous Ceramics seminar and technical writing
Porous Ceramics seminar and technical writing
 
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
 
(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
 
247267395-1-Symmetric-and-distributed-shared-memory-architectures-ppt (1).ppt
247267395-1-Symmetric-and-distributed-shared-memory-architectures-ppt (1).ppt247267395-1-Symmetric-and-distributed-shared-memory-architectures-ppt (1).ppt
247267395-1-Symmetric-and-distributed-shared-memory-architectures-ppt (1).ppt
 
Introduction to Multiple Access Protocol.pptx
Introduction to Multiple Access Protocol.pptxIntroduction to Multiple Access Protocol.pptx
Introduction to Multiple Access Protocol.pptx
 
Introduction and different types of Ethernet.pptx
Introduction and different types of Ethernet.pptxIntroduction and different types of Ethernet.pptx
Introduction and different types of Ethernet.pptx
 
(RIA) Call Girls Bhosari ( 7001035870 ) HI-Fi Pune Escorts Service
(RIA) Call Girls Bhosari ( 7001035870 ) HI-Fi Pune Escorts Service(RIA) Call Girls Bhosari ( 7001035870 ) HI-Fi Pune Escorts Service
(RIA) Call Girls Bhosari ( 7001035870 ) HI-Fi Pune Escorts Service
 
UNIT - IV - Air Compressors and its Performance
UNIT - IV - Air Compressors and its PerformanceUNIT - IV - Air Compressors and its Performance
UNIT - IV - Air Compressors and its Performance
 
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur Escorts
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur EscortsCall Girls in Nagpur Suman Call 7001035870 Meet With Nagpur Escorts
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur Escorts
 
(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...
(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...
(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...
 
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur EscortsHigh Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escorts
 
VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130
VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130
VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130
 
Microscopic Analysis of Ceramic Materials.pptx
Microscopic Analysis of Ceramic Materials.pptxMicroscopic Analysis of Ceramic Materials.pptx
Microscopic Analysis of Ceramic Materials.pptx
 
Coefficient of Thermal Expansion and their Importance.pptx
Coefficient of Thermal Expansion and their Importance.pptxCoefficient of Thermal Expansion and their Importance.pptx
Coefficient of Thermal Expansion and their Importance.pptx
 
Extrusion Processes and Their Limitations
Extrusion Processes and Their LimitationsExtrusion Processes and Their Limitations
Extrusion Processes and Their Limitations
 
SPICE PARK APR2024 ( 6,793 SPICE Models )
SPICE PARK APR2024 ( 6,793 SPICE Models )SPICE PARK APR2024 ( 6,793 SPICE Models )
SPICE PARK APR2024 ( 6,793 SPICE Models )
 

string in C

  • 1. C STRING By:Er. Anupam Sharma Assistant Professor anupamcgctc@gmail.com
  • 2. C - STRING  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."  strings are arrays of chars. String literals are words surrounded by double quotation marks. "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 WITHOUTUSING 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 Target string = is fun = C tutorial Target string after strcat( ) = C tutorial is fun
  • 23. Thanks for your time and attention!