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

PPT
RECURSION IN C
PPT
Pointers C programming
PPT
File handling in c
PPTX
PPTX
Loops in c programming
PDF
Character Array and String
PPTX
Functions in c
PPTX
Conversion of Infix to Prefix and Postfix with Stack
RECURSION IN C
Pointers C programming
File handling in c
Loops in c programming
Character Array and String
Functions in c
Conversion of Infix to Prefix and Postfix with Stack

What's hot (20)

PPTX
PPTX
Structure in C
PPTX
PPTX
Function overloading
PPTX
Recursive Function
PPT
Stacks
PPTX
C++ string
PPTX
CONDITIONAL STATEMENT IN C LANGUAGE
PPSX
Break and continue
PDF
Function overloading ppt
PPTX
Type casting in c programming
PPTX
Pointers in C Programming
PPTX
C++ presentation
PPT
Strings
PPT
structure and union
PDF
Constructors and Destructors
PPTX
C Programming Unit-5
PPTX
C Tokens
PPTX
Pointer in C++
Structure in C
Function overloading
Recursive Function
Stacks
C++ string
CONDITIONAL STATEMENT IN C LANGUAGE
Break and continue
Function overloading ppt
Type casting in c programming
Pointers in C Programming
C++ presentation
Strings
structure and union
Constructors and Destructors
C Programming Unit-5
C Tokens
Pointer in C++
Ad

Viewers also liked (20)

PPT
Strings In OOP(Object oriented programming)
PPTX
C programming - String
PPSX
C programming string
PPT
Handling Exceptions In C & C++ [Part B] Ver 2
PDF
05 c++-strings
PDF
PPTX
String Handling in c++
PPT
Handling Exceptions In C & C++[Part A]
PPTX
Exception Handling in C++
PPT
PPT
Exception handling and templates
PPT
Exception handling in c++ by manoj vasava
DOC
String in c
PPTX
C vs c++
PPSX
Exception Handling
PPTX
Exception handling
PPT
Unit 2 Principles of Programming Languages
ODP
Ppt of c++ vs c#
PDF
C notes.pdf
PPTX
Unit1 principle of programming language
Strings In OOP(Object oriented programming)
C programming - String
C programming string
Handling Exceptions In C & C++ [Part B] Ver 2
05 c++-strings
String Handling in c++
Handling Exceptions In C & C++[Part A]
Exception Handling in C++
Exception handling and templates
Exception handling in c++ by manoj vasava
String in c
C vs c++
Exception Handling
Exception handling
Unit 2 Principles of Programming Languages
Ppt of c++ vs c#
C notes.pdf
Unit1 principle of programming language
Ad

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

PPTX
Presentation more c_programmingcharacter_and_string_handling_
PPT
14 strings
PPT
String manipulation techniques like string compare copy
PPT
CPSTRINGSARGAVISTRINGS.PPT
PPT
BHARGAVISTRINGS.PPT
PPT
CP-STRING.ppt
PPT
CP-STRING (1).ppt
PPT
CP-STRING.ppt
PPTX
Slide -231, Math-1151, lecture-15,Chapter, Chapter 2.2,2.3, 5.1,5.2,5.6.pptx
PPTX
Strings cprogramminglanguagedsasheet.pptx
PPTX
String in c programming
PPTX
Module-2_Strings concepts in c programming
PPT
Strings
PDF
[ITP - Lecture 17] Strings in C/C++
PPTX
CSE 1102 - Lecture_7 - Strings_in_C.pptx
PPTX
String_Slide.pptxStructure.pptxStructure.pptxStructure.pptxStructure.pptx
PPTX
C - String ppt
PDF
0-Slot21-22-Strings.pdf
PPTX
Strings CPU GTU
Presentation more c_programmingcharacter_and_string_handling_
14 strings
String manipulation techniques like string compare copy
CPSTRINGSARGAVISTRINGS.PPT
BHARGAVISTRINGS.PPT
CP-STRING.ppt
CP-STRING (1).ppt
CP-STRING.ppt
Slide -231, Math-1151, lecture-15,Chapter, Chapter 2.2,2.3, 5.1,5.2,5.6.pptx
Strings cprogramminglanguagedsasheet.pptx
String in c programming
Module-2_Strings concepts in c programming
Strings
[ITP - Lecture 17] Strings in C/C++
CSE 1102 - Lecture_7 - Strings_in_C.pptx
String_Slide.pptxStructure.pptxStructure.pptxStructure.pptxStructure.pptx
C - String ppt
0-Slot21-22-Strings.pdf
Strings CPU GTU

More from Samsil Arefin (20)

PPTX
Transmission Control Protocol and User Datagram protocol
PDF
Evolution Phylogenetic
PPTX
Evolution Phylogenetic
PDF
Ego net facebook data analysis
PPTX
Augmented Reality (AR)
PPTX
Client server chat application
PPTX
Strings in programming tutorial.
PDF
Linked list searching deleting inserting
PPTX
Number theory
PDF
Program to sort the n names in an alphabetical order
PDF
Linked list int_data_fdata
PDF
Linked list Output tracing
PDF
PPT
Sorting
PPTX
Fundamentals of-electric-circuit
PPTX
Cyber security
PDF
C programming
PPTX
Data structure lecture 1
PPT
Structure and union
PPT
Structure in programming in c or c++ or c# or java
Transmission Control Protocol and User Datagram protocol
Evolution Phylogenetic
Evolution Phylogenetic
Ego net facebook data analysis
Augmented Reality (AR)
Client server chat application
Strings in programming tutorial.
Linked list searching deleting inserting
Number theory
Program to sort the n names in an alphabetical order
Linked list int_data_fdata
Linked list Output tracing
Sorting
Fundamentals of-electric-circuit
Cyber security
C programming
Data structure lecture 1
Structure and union
Structure in programming in c or c++ or c# or java

Recently uploaded (20)

PDF
July 2025 - Top 10 Read Articles in International Journal of Software Enginee...
PPT
Mechanical Engineering MATERIALS Selection
PDF
Model Code of Practice - Construction Work - 21102022 .pdf
PPTX
OOP with Java - Java Introduction (Basics)
PPTX
M Tech Sem 1 Civil Engineering Environmental Sciences.pptx
PPTX
Sustainable Sites - Green Building Construction
PPTX
UNIT-1 - COAL BASED THERMAL POWER PLANTS
PPTX
MET 305 2019 SCHEME MODULE 2 COMPLETE.pptx
PDF
Operating System & Kernel Study Guide-1 - converted.pdf
PPTX
bas. eng. economics group 4 presentation 1.pptx
PDF
Evaluating the Democratization of the Turkish Armed Forces from a Normative P...
PPTX
Infosys Presentation by1.Riyan Bagwan 2.Samadhan Naiknavare 3.Gaurav Shinde 4...
PDF
keyrequirementskkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkk
PPTX
Lecture Notes Electrical Wiring System Components
PPTX
CH1 Production IntroductoryConcepts.pptx
PDF
Embodied AI: Ushering in the Next Era of Intelligent Systems
PDF
BMEC211 - INTRODUCTION TO MECHATRONICS-1.pdf
PDF
PPT on Performance Review to get promotions
PPTX
Recipes for Real Time Voice AI WebRTC, SLMs and Open Source Software.pptx
PPTX
Strings in CPP - Strings in C++ are sequences of characters used to store and...
July 2025 - Top 10 Read Articles in International Journal of Software Enginee...
Mechanical Engineering MATERIALS Selection
Model Code of Practice - Construction Work - 21102022 .pdf
OOP with Java - Java Introduction (Basics)
M Tech Sem 1 Civil Engineering Environmental Sciences.pptx
Sustainable Sites - Green Building Construction
UNIT-1 - COAL BASED THERMAL POWER PLANTS
MET 305 2019 SCHEME MODULE 2 COMPLETE.pptx
Operating System & Kernel Study Guide-1 - converted.pdf
bas. eng. economics group 4 presentation 1.pptx
Evaluating the Democratization of the Turkish Armed Forces from a Normative P...
Infosys Presentation by1.Riyan Bagwan 2.Samadhan Naiknavare 3.Gaurav Shinde 4...
keyrequirementskkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkk
Lecture Notes Electrical Wiring System Components
CH1 Production IntroductoryConcepts.pptx
Embodied AI: Ushering in the Next Era of Intelligent Systems
BMEC211 - INTRODUCTION TO MECHATRONICS-1.pdf
PPT on Performance Review to get promotions
Recipes for Real Time Voice AI WebRTC, SLMs and Open Source Software.pptx
Strings in CPP - Strings in C++ are sequences of characters used to store and...

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