SlideShare a Scribd company logo
Strings
Md. Imran Hossain Showrov (showrovsworld@gmail.com)
17
1
Outline
 What is a String?
 Defining A String
 What is NULL Character?
 Initialization of a String
 Reading and Writing a String
What is a String?
 The array represents a list of elements of the same
data type.
 Most of the programming languages handle array of
characters with a special provision for stings.
 Strings are actually one-dimensional array of
characters terminated by a null character (represent
as '0‘).
What is a String?
 null character is also named as string termination
character. It is used to identify the length of the string
 Initially, the string is nothing but an array of individual
characters, and each individual element is accessible
via subscripts.
Defining A String
 A string definition may be expressed as
storage-class char string-name [expression];
Example:
char greeting[6] = {'H', 'e', 'l', 'l', 'o', '0'};
String Example1
char name[50];
/* name is a string that can consist of maximum 50
characters */
static char address[100];
/* address is a static string of maximum 100 characters
*/
String Example2
char greeting[] = "Hello";
Following is the memory presentation of the above defined string in C/C++
 Actually, we 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.
What is NULL Character
 One of the most important issues in handling strings
is null character.
 Null character is used to terminate the string.
 It is needed to compute the actual length of the
string.
 The string definition specifies the maximum length
support. i.e. 50 in case of name[50] defines the
maximum length of name.
What is NULL Character (cont..)
 Example:
char name [50] = “Jitender”;
 In this example, the length of actual stored string is 8.
In that case 9th element of the array i.e. name[8]
location will be used to stored null character.
J i t e n d e r ‘0’ ……………
[0] [1] [2] [3] [4] [5] [6] [7] [8] [49]
What is NULL Character (cont..)
 The null character is not counted towards the length
of the string, but takes memory of one element.
 Null character cannot be read or written, but is used
internally only.
Initialization of a String
 The string can be initialized as follows: -
char str[30] = “Hello World”;
char str[30] = {‘H’,‘e’,‘l’,‘l’,‘o’,‘ ’,‘W’,‘o’,‘r’,‘l’,‘d’};
H e l l o W o r l d 0 …………..
str [0] [1] [2] [3] [4] [5] [6] [7] [8] [9] [10] [11] [29]
Reading and Writing a String
 A string can be read and written by using a single
scanf and printf function using %s (s stands for string)
and no loop in needed, which was compulsory for
reading and writing arrays of other types.
Reading and Writing a String (Example)
#include<stdio.h>
#define MAX_SIZE 50
main()
{
char str [MAX_SIZE];
printf(“Enter a string of maximum %d characters: ”, MAX_SIZE);
scanf(“%s”, str); /* no ampersand (&) is used here*/
printf(“The entered string is %sn”, str);
}
 After the reading is complete, the null character is appended automatically at the
next position inside the array.
Processing the String
Functions are used to process with help of string.h header file or by processing
all characters individually.
1. int strlen (string_var): to compute the length of the string, not counting
null character.
2. strcpy (dst_string, src_string): to copy a source string into destination
string
3. int strcmp(str1, str2): to compare str1 with str2
4. strcat(dst_string, src_string): to append copy of the source string at the
end of destination string
Here, dst_string = destination string
src_string = source string
Lecture 17 - Strings
Ad

More Related Content

What's hot (20)

Lecture 15 - Array
Lecture 15 - ArrayLecture 15 - Array
Lecture 15 - Array
Md. Imran Hossain Showrov
 
C Programming Unit-3
C Programming Unit-3C Programming Unit-3
C Programming Unit-3
Vikram Nandini
 
detailed information about Pointers in c language
detailed information about Pointers in c languagedetailed information about Pointers in c language
detailed information about Pointers in c language
gourav kottawar
 
C programming - Pointers
C programming - PointersC programming - Pointers
C programming - Pointers
Wingston
 
Pointers in C
Pointers in CPointers in C
Pointers in C
Vijayananda Ratnam Ch
 
Module 02 Pointers in C
Module 02 Pointers in CModule 02 Pointers in C
Module 02 Pointers in C
Tushar B Kute
 
Types of pointer in C
Types of pointer in CTypes of pointer in C
Types of pointer in C
rgnikate
 
Pointers in C
Pointers in CPointers in C
Pointers in C
guestdc3f16
 
Lecturer23 pointersin c.ppt
Lecturer23 pointersin c.pptLecturer23 pointersin c.ppt
Lecturer23 pointersin c.ppt
eShikshak
 
Pointers
PointersPointers
Pointers
PreethyJemima
 
Pointer in C
Pointer in CPointer in C
Pointer in C
Sonya Akter Rupa
 
Pointer
PointerPointer
Pointer
Learn By Watch
 
Dynamic Memory Allocation in C
Dynamic Memory Allocation in CDynamic Memory Allocation in C
Dynamic Memory Allocation in C
Vijayananda Ratnam Ch
 
C pointer basics
C pointer basicsC pointer basics
C pointer basics
Software Systems and Graphic Designs
 
Pointers in C
Pointers in CPointers in C
Pointers in C
Kamal Acharya
 
Pointers_c
Pointers_cPointers_c
Pointers_c
ahmed safwat
 
[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++
Muhammad Hammad Waseem
 
[ITP - Lecture 16] Structures in C/C++
[ITP - Lecture 16] Structures in C/C++[ITP - Lecture 16] Structures in C/C++
[ITP - Lecture 16] Structures in C/C++
Muhammad Hammad Waseem
 
Pointers+(2)
Pointers+(2)Pointers+(2)
Pointers+(2)
Rubal Bansal
 
Strings
StringsStrings
Strings
Saranya saran
 

Similar to Lecture 17 - Strings (20)

Strings in programming tutorial.
Strings  in programming tutorial.Strings  in programming tutorial.
Strings in programming tutorial.
Samsil Arefin
 
String notes
String notesString notes
String notes
Prasadu Peddi
 
9 character string &amp; string library
9  character string &amp; string library9  character string &amp; string library
9 character string &amp; string library
MomenMostafa
 
introduction to strings in c programming
introduction to strings in c programmingintroduction to strings in c programming
introduction to strings in c programming
mikeymanjiro2090
 
Strings in c mrs.sowmya jyothi
Strings in c mrs.sowmya jyothiStrings in c mrs.sowmya jyothi
Strings in c mrs.sowmya jyothi
Sowmya Jyothi
 
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
SowmyaJyothi3
 
Chapter 4 (Part II) - Array and Strings.pdf
Chapter 4 (Part II) - Array and Strings.pdfChapter 4 (Part II) - Array and Strings.pdf
Chapter 4 (Part II) - Array and Strings.pdf
KirubelWondwoson1
 
Strings in C
Strings in CStrings in C
Strings in C
Kamal Acharya
 
ARRAY's in C Programming Language PPTX.
ARRAY's in C  Programming Language PPTX.ARRAY's in C  Programming Language PPTX.
ARRAY's in C Programming Language PPTX.
MSridhar18
 
Cfbcgdhfghdfhghggfhghghgfhgfhgfhhapter11.PPT
Cfbcgdhfghdfhghggfhghghgfhgfhgfhhapter11.PPTCfbcgdhfghdfhghggfhghghgfhgfhgfhhapter11.PPT
Cfbcgdhfghdfhghggfhghghgfhgfhgfhhapter11.PPT
JITENDER773791
 
strings-150319180934-conversion-gate01.pdf
strings-150319180934-conversion-gate01.pdfstrings-150319180934-conversion-gate01.pdf
strings-150319180934-conversion-gate01.pdf
HEMAHEMS5
 
Chapterabcdefghijklmnopqrdstuvwxydanniipo
ChapterabcdefghijklmnopqrdstuvwxydanniipoChapterabcdefghijklmnopqrdstuvwxydanniipo
Chapterabcdefghijklmnopqrdstuvwxydanniipo
abritip
 
COm1407: Character & Strings
COm1407: Character & StringsCOm1407: Character & Strings
COm1407: Character & Strings
Hemantha Kulathilake
 
CP-STRING (1).ppt
CP-STRING (1).pptCP-STRING (1).ppt
CP-STRING (1).ppt
mounikanarra3
 
CP-STRING.ppt
CP-STRING.pptCP-STRING.ppt
CP-STRING.ppt
TAPANDDRAW
 
CP-STRING.ppt
CP-STRING.pptCP-STRING.ppt
CP-STRING.ppt
arunatluri
 
String in c
String in cString in c
String in c
Suneel Dogra
 
Programming in C - Fundamental Study of Strings
Programming in C - Fundamental Study of  StringsProgramming in C - Fundamental Study of  Strings
Programming in C - Fundamental Study of Strings
Dr. Chandrakant Divate
 
Strings
StringsStrings
Strings
Mitali Chugh
 
Strings In C and its syntax and uses .ppt
Strings In C and its syntax and uses .pptStrings In C and its syntax and uses .ppt
Strings In C and its syntax and uses .ppt
fallengaming1606
 
Strings in programming tutorial.
Strings  in programming tutorial.Strings  in programming tutorial.
Strings in programming tutorial.
Samsil Arefin
 
9 character string &amp; string library
9  character string &amp; string library9  character string &amp; string library
9 character string &amp; string library
MomenMostafa
 
introduction to strings in c programming
introduction to strings in c programmingintroduction to strings in c programming
introduction to strings in c programming
mikeymanjiro2090
 
Strings in c mrs.sowmya jyothi
Strings in c mrs.sowmya jyothiStrings in c mrs.sowmya jyothi
Strings in c mrs.sowmya jyothi
Sowmya Jyothi
 
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
SowmyaJyothi3
 
Chapter 4 (Part II) - Array and Strings.pdf
Chapter 4 (Part II) - Array and Strings.pdfChapter 4 (Part II) - Array and Strings.pdf
Chapter 4 (Part II) - Array and Strings.pdf
KirubelWondwoson1
 
ARRAY's in C Programming Language PPTX.
ARRAY's in C  Programming Language PPTX.ARRAY's in C  Programming Language PPTX.
ARRAY's in C Programming Language PPTX.
MSridhar18
 
Cfbcgdhfghdfhghggfhghghgfhgfhgfhhapter11.PPT
Cfbcgdhfghdfhghggfhghghgfhgfhgfhhapter11.PPTCfbcgdhfghdfhghggfhghghgfhgfhgfhhapter11.PPT
Cfbcgdhfghdfhghggfhghghgfhgfhgfhhapter11.PPT
JITENDER773791
 
strings-150319180934-conversion-gate01.pdf
strings-150319180934-conversion-gate01.pdfstrings-150319180934-conversion-gate01.pdf
strings-150319180934-conversion-gate01.pdf
HEMAHEMS5
 
Chapterabcdefghijklmnopqrdstuvwxydanniipo
ChapterabcdefghijklmnopqrdstuvwxydanniipoChapterabcdefghijklmnopqrdstuvwxydanniipo
Chapterabcdefghijklmnopqrdstuvwxydanniipo
abritip
 
Programming in C - Fundamental Study of Strings
Programming in C - Fundamental Study of  StringsProgramming in C - Fundamental Study of  Strings
Programming in C - Fundamental Study of Strings
Dr. Chandrakant Divate
 
Strings In C and its syntax and uses .ppt
Strings In C and its syntax and uses .pptStrings In C and its syntax and uses .ppt
Strings In C and its syntax and uses .ppt
fallengaming1606
 
Ad

More from Md. Imran Hossain Showrov (15)

Lecture 22 - Error Handling
Lecture 22 - Error HandlingLecture 22 - Error Handling
Lecture 22 - Error Handling
Md. Imran Hossain Showrov
 
Lecture 21 - Preprocessor and Header File
Lecture 21 - Preprocessor and Header FileLecture 21 - Preprocessor and Header File
Lecture 21 - Preprocessor and Header File
Md. Imran Hossain Showrov
 
Lecture 20 - File Handling
Lecture 20 - File HandlingLecture 20 - File Handling
Lecture 20 - File Handling
Md. Imran Hossain Showrov
 
Lecture 19 - Struct and Union
Lecture 19 - Struct and UnionLecture 19 - Struct and Union
Lecture 19 - Struct and Union
Md. Imran Hossain Showrov
 
Lecture 16 - Multi dimensional Array
Lecture 16 - Multi dimensional ArrayLecture 16 - Multi dimensional Array
Lecture 16 - Multi dimensional Array
Md. Imran Hossain Showrov
 
Lecture 14 - Scope Rules
Lecture 14 - Scope RulesLecture 14 - Scope Rules
Lecture 14 - Scope Rules
Md. Imran Hossain Showrov
 
Lecture 13 - Storage Classes
Lecture 13 - Storage ClassesLecture 13 - Storage Classes
Lecture 13 - Storage Classes
Md. Imran Hossain Showrov
 
Lecture 11 - Functions
Lecture 11 - FunctionsLecture 11 - Functions
Lecture 11 - Functions
Md. Imran Hossain Showrov
 
Lecture 9- Control Structures 1
Lecture 9- Control Structures 1Lecture 9- Control Structures 1
Lecture 9- Control Structures 1
Md. Imran Hossain Showrov
 
Lecture 7- Operators and Expressions
Lecture 7- Operators and Expressions Lecture 7- Operators and Expressions
Lecture 7- Operators and Expressions
Md. Imran Hossain Showrov
 
Lecture 5 - Structured Programming Language
Lecture 5 - Structured Programming Language Lecture 5 - Structured Programming Language
Lecture 5 - Structured Programming Language
Md. Imran Hossain Showrov
 
Lecture 4- Computer Software and Languages
Lecture 4- Computer Software and LanguagesLecture 4- Computer Software and Languages
Lecture 4- Computer Software and Languages
Md. Imran Hossain Showrov
 
Lecture 3 - Processors, Memory and I/O devices
Lecture 3 - Processors, Memory and I/O devicesLecture 3 - Processors, Memory and I/O devices
Lecture 3 - Processors, Memory and I/O devices
Md. Imran Hossain Showrov
 
Lecture 2 - Introductory Concepts
Lecture 2 - Introductory ConceptsLecture 2 - Introductory Concepts
Lecture 2 - Introductory Concepts
Md. Imran Hossain Showrov
 
Lecture 1- History of C Programming
Lecture 1- History of C Programming Lecture 1- History of C Programming
Lecture 1- History of C Programming
Md. Imran Hossain Showrov
 
Ad

Recently uploaded (20)

Ajanta Paintings: Study as a Source of History
Ajanta Paintings: Study as a Source of HistoryAjanta Paintings: Study as a Source of History
Ajanta Paintings: Study as a Source of History
Virag Sontakke
 
ANTI-VIRAL DRUGS unit 3 Pharmacology 3.pptx
ANTI-VIRAL DRUGS unit 3 Pharmacology 3.pptxANTI-VIRAL DRUGS unit 3 Pharmacology 3.pptx
ANTI-VIRAL DRUGS unit 3 Pharmacology 3.pptx
Mayuri Chavan
 
MCQ PHYSIOLOGY II (DR. NASIR MUSTAFA) MCQS)
MCQ PHYSIOLOGY II (DR. NASIR MUSTAFA) MCQS)MCQ PHYSIOLOGY II (DR. NASIR MUSTAFA) MCQS)
MCQ PHYSIOLOGY II (DR. NASIR MUSTAFA) MCQS)
Dr. Nasir Mustafa
 
spinal cord disorders (Myelopathies and radiculoapthies)
spinal cord disorders (Myelopathies and radiculoapthies)spinal cord disorders (Myelopathies and radiculoapthies)
spinal cord disorders (Myelopathies and radiculoapthies)
Mohamed Rizk Khodair
 
Myopathies (muscle disorders) for undergraduate
Myopathies (muscle disorders) for undergraduateMyopathies (muscle disorders) for undergraduate
Myopathies (muscle disorders) for undergraduate
Mohamed Rizk Khodair
 
How to Manage Upselling in Odoo 18 Sales
How to Manage Upselling in Odoo 18 SalesHow to Manage Upselling in Odoo 18 Sales
How to Manage Upselling in Odoo 18 Sales
Celine George
 
U3 ANTITUBERCULAR DRUGS Pharmacology 3.pptx
U3 ANTITUBERCULAR DRUGS Pharmacology 3.pptxU3 ANTITUBERCULAR DRUGS Pharmacology 3.pptx
U3 ANTITUBERCULAR DRUGS Pharmacology 3.pptx
Mayuri Chavan
 
Form View Attributes in Odoo 18 - Odoo Slides
Form View Attributes in Odoo 18 - Odoo SlidesForm View Attributes in Odoo 18 - Odoo Slides
Form View Attributes in Odoo 18 - Odoo Slides
Celine George
 
How to Configure Scheduled Actions in odoo 18
How to Configure Scheduled Actions in odoo 18How to Configure Scheduled Actions in odoo 18
How to Configure Scheduled Actions in odoo 18
Celine George
 
TERMINOLOGIES,GRIEF PROCESS AND LOSS AMD ITS TYPES .pptx
TERMINOLOGIES,GRIEF PROCESS AND LOSS AMD ITS TYPES .pptxTERMINOLOGIES,GRIEF PROCESS AND LOSS AMD ITS TYPES .pptx
TERMINOLOGIES,GRIEF PROCESS AND LOSS AMD ITS TYPES .pptx
PoojaSen20
 
antiquity of writing in ancient India- literary & archaeological evidence
antiquity of writing in ancient India- literary & archaeological evidenceantiquity of writing in ancient India- literary & archaeological evidence
antiquity of writing in ancient India- literary & archaeological evidence
PrachiSontakke5
 
BÀI TẬP BỔ TRỢ TIẾNG ANH 9 THEO ĐƠN VỊ BÀI HỌC - GLOBAL SUCCESS - CẢ NĂM (TỪ...
BÀI TẬP BỔ TRỢ TIẾNG ANH 9 THEO ĐƠN VỊ BÀI HỌC - GLOBAL SUCCESS - CẢ NĂM (TỪ...BÀI TẬP BỔ TRỢ TIẾNG ANH 9 THEO ĐƠN VỊ BÀI HỌC - GLOBAL SUCCESS - CẢ NĂM (TỪ...
BÀI TẬP BỔ TRỢ TIẾNG ANH 9 THEO ĐƠN VỊ BÀI HỌC - GLOBAL SUCCESS - CẢ NĂM (TỪ...
Nguyen Thanh Tu Collection
 
How to Configure Public Holidays & Mandatory Days in Odoo 18
How to Configure Public Holidays & Mandatory Days in Odoo 18How to Configure Public Holidays & Mandatory Days in Odoo 18
How to Configure Public Holidays & Mandatory Days in Odoo 18
Celine George
 
How to Create Kanban View in Odoo 18 - Odoo Slides
How to Create Kanban View in Odoo 18 - Odoo SlidesHow to Create Kanban View in Odoo 18 - Odoo Slides
How to Create Kanban View in Odoo 18 - Odoo Slides
Celine George
 
*"Sensing the World: Insect Sensory Systems"*
*"Sensing the World: Insect Sensory Systems"**"Sensing the World: Insect Sensory Systems"*
*"Sensing the World: Insect Sensory Systems"*
Arshad Shaikh
 
Overview Well-Being and Creative Careers
Overview Well-Being and Creative CareersOverview Well-Being and Creative Careers
Overview Well-Being and Creative Careers
University of Amsterdam
 
Rock Art As a Source of Ancient Indian History
Rock Art As a Source of Ancient Indian HistoryRock Art As a Source of Ancient Indian History
Rock Art As a Source of Ancient Indian History
Virag Sontakke
 
CNS infections (encephalitis, meningitis & Brain abscess
CNS infections (encephalitis, meningitis & Brain abscessCNS infections (encephalitis, meningitis & Brain abscess
CNS infections (encephalitis, meningitis & Brain abscess
Mohamed Rizk Khodair
 
How to Manage Amounts in Local Currency in Odoo 18 Purchase
How to Manage Amounts in Local Currency in Odoo 18 PurchaseHow to Manage Amounts in Local Currency in Odoo 18 Purchase
How to Manage Amounts in Local Currency in Odoo 18 Purchase
Celine George
 
Ajanta Paintings: Study as a Source of History
Ajanta Paintings: Study as a Source of HistoryAjanta Paintings: Study as a Source of History
Ajanta Paintings: Study as a Source of History
Virag Sontakke
 
ANTI-VIRAL DRUGS unit 3 Pharmacology 3.pptx
ANTI-VIRAL DRUGS unit 3 Pharmacology 3.pptxANTI-VIRAL DRUGS unit 3 Pharmacology 3.pptx
ANTI-VIRAL DRUGS unit 3 Pharmacology 3.pptx
Mayuri Chavan
 
MCQ PHYSIOLOGY II (DR. NASIR MUSTAFA) MCQS)
MCQ PHYSIOLOGY II (DR. NASIR MUSTAFA) MCQS)MCQ PHYSIOLOGY II (DR. NASIR MUSTAFA) MCQS)
MCQ PHYSIOLOGY II (DR. NASIR MUSTAFA) MCQS)
Dr. Nasir Mustafa
 
spinal cord disorders (Myelopathies and radiculoapthies)
spinal cord disorders (Myelopathies and radiculoapthies)spinal cord disorders (Myelopathies and radiculoapthies)
spinal cord disorders (Myelopathies and radiculoapthies)
Mohamed Rizk Khodair
 
Myopathies (muscle disorders) for undergraduate
Myopathies (muscle disorders) for undergraduateMyopathies (muscle disorders) for undergraduate
Myopathies (muscle disorders) for undergraduate
Mohamed Rizk Khodair
 
How to Manage Upselling in Odoo 18 Sales
How to Manage Upselling in Odoo 18 SalesHow to Manage Upselling in Odoo 18 Sales
How to Manage Upselling in Odoo 18 Sales
Celine George
 
U3 ANTITUBERCULAR DRUGS Pharmacology 3.pptx
U3 ANTITUBERCULAR DRUGS Pharmacology 3.pptxU3 ANTITUBERCULAR DRUGS Pharmacology 3.pptx
U3 ANTITUBERCULAR DRUGS Pharmacology 3.pptx
Mayuri Chavan
 
Form View Attributes in Odoo 18 - Odoo Slides
Form View Attributes in Odoo 18 - Odoo SlidesForm View Attributes in Odoo 18 - Odoo Slides
Form View Attributes in Odoo 18 - Odoo Slides
Celine George
 
How to Configure Scheduled Actions in odoo 18
How to Configure Scheduled Actions in odoo 18How to Configure Scheduled Actions in odoo 18
How to Configure Scheduled Actions in odoo 18
Celine George
 
TERMINOLOGIES,GRIEF PROCESS AND LOSS AMD ITS TYPES .pptx
TERMINOLOGIES,GRIEF PROCESS AND LOSS AMD ITS TYPES .pptxTERMINOLOGIES,GRIEF PROCESS AND LOSS AMD ITS TYPES .pptx
TERMINOLOGIES,GRIEF PROCESS AND LOSS AMD ITS TYPES .pptx
PoojaSen20
 
antiquity of writing in ancient India- literary & archaeological evidence
antiquity of writing in ancient India- literary & archaeological evidenceantiquity of writing in ancient India- literary & archaeological evidence
antiquity of writing in ancient India- literary & archaeological evidence
PrachiSontakke5
 
BÀI TẬP BỔ TRỢ TIẾNG ANH 9 THEO ĐƠN VỊ BÀI HỌC - GLOBAL SUCCESS - CẢ NĂM (TỪ...
BÀI TẬP BỔ TRỢ TIẾNG ANH 9 THEO ĐƠN VỊ BÀI HỌC - GLOBAL SUCCESS - CẢ NĂM (TỪ...BÀI TẬP BỔ TRỢ TIẾNG ANH 9 THEO ĐƠN VỊ BÀI HỌC - GLOBAL SUCCESS - CẢ NĂM (TỪ...
BÀI TẬP BỔ TRỢ TIẾNG ANH 9 THEO ĐƠN VỊ BÀI HỌC - GLOBAL SUCCESS - CẢ NĂM (TỪ...
Nguyen Thanh Tu Collection
 
How to Configure Public Holidays & Mandatory Days in Odoo 18
How to Configure Public Holidays & Mandatory Days in Odoo 18How to Configure Public Holidays & Mandatory Days in Odoo 18
How to Configure Public Holidays & Mandatory Days in Odoo 18
Celine George
 
How to Create Kanban View in Odoo 18 - Odoo Slides
How to Create Kanban View in Odoo 18 - Odoo SlidesHow to Create Kanban View in Odoo 18 - Odoo Slides
How to Create Kanban View in Odoo 18 - Odoo Slides
Celine George
 
*"Sensing the World: Insect Sensory Systems"*
*"Sensing the World: Insect Sensory Systems"**"Sensing the World: Insect Sensory Systems"*
*"Sensing the World: Insect Sensory Systems"*
Arshad Shaikh
 
Overview Well-Being and Creative Careers
Overview Well-Being and Creative CareersOverview Well-Being and Creative Careers
Overview Well-Being and Creative Careers
University of Amsterdam
 
Rock Art As a Source of Ancient Indian History
Rock Art As a Source of Ancient Indian HistoryRock Art As a Source of Ancient Indian History
Rock Art As a Source of Ancient Indian History
Virag Sontakke
 
CNS infections (encephalitis, meningitis & Brain abscess
CNS infections (encephalitis, meningitis & Brain abscessCNS infections (encephalitis, meningitis & Brain abscess
CNS infections (encephalitis, meningitis & Brain abscess
Mohamed Rizk Khodair
 
How to Manage Amounts in Local Currency in Odoo 18 Purchase
How to Manage Amounts in Local Currency in Odoo 18 PurchaseHow to Manage Amounts in Local Currency in Odoo 18 Purchase
How to Manage Amounts in Local Currency in Odoo 18 Purchase
Celine George
 

Lecture 17 - Strings

  • 1. Strings Md. Imran Hossain Showrov (showrovsworld@gmail.com) 17 1
  • 2. Outline  What is a String?  Defining A String  What is NULL Character?  Initialization of a String  Reading and Writing a String
  • 3. What is a String?  The array represents a list of elements of the same data type.  Most of the programming languages handle array of characters with a special provision for stings.  Strings are actually one-dimensional array of characters terminated by a null character (represent as '0‘).
  • 4. What is a String?  null character is also named as string termination character. It is used to identify the length of the string  Initially, the string is nothing but an array of individual characters, and each individual element is accessible via subscripts.
  • 5. Defining A String  A string definition may be expressed as storage-class char string-name [expression]; Example: char greeting[6] = {'H', 'e', 'l', 'l', 'o', '0'};
  • 6. String Example1 char name[50]; /* name is a string that can consist of maximum 50 characters */ static char address[100]; /* address is a static string of maximum 100 characters */
  • 7. String Example2 char greeting[] = "Hello"; Following is the memory presentation of the above defined string in C/C++  Actually, we 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.
  • 8. What is NULL Character  One of the most important issues in handling strings is null character.  Null character is used to terminate the string.  It is needed to compute the actual length of the string.  The string definition specifies the maximum length support. i.e. 50 in case of name[50] defines the maximum length of name.
  • 9. What is NULL Character (cont..)  Example: char name [50] = “Jitender”;  In this example, the length of actual stored string is 8. In that case 9th element of the array i.e. name[8] location will be used to stored null character. J i t e n d e r ‘0’ …………… [0] [1] [2] [3] [4] [5] [6] [7] [8] [49]
  • 10. What is NULL Character (cont..)  The null character is not counted towards the length of the string, but takes memory of one element.  Null character cannot be read or written, but is used internally only.
  • 11. Initialization of a String  The string can be initialized as follows: - char str[30] = “Hello World”; char str[30] = {‘H’,‘e’,‘l’,‘l’,‘o’,‘ ’,‘W’,‘o’,‘r’,‘l’,‘d’}; H e l l o W o r l d 0 ………….. str [0] [1] [2] [3] [4] [5] [6] [7] [8] [9] [10] [11] [29]
  • 12. Reading and Writing a String  A string can be read and written by using a single scanf and printf function using %s (s stands for string) and no loop in needed, which was compulsory for reading and writing arrays of other types.
  • 13. Reading and Writing a String (Example) #include<stdio.h> #define MAX_SIZE 50 main() { char str [MAX_SIZE]; printf(“Enter a string of maximum %d characters: ”, MAX_SIZE); scanf(“%s”, str); /* no ampersand (&) is used here*/ printf(“The entered string is %sn”, str); }  After the reading is complete, the null character is appended automatically at the next position inside the array.
  • 14. Processing the String Functions are used to process with help of string.h header file or by processing all characters individually. 1. int strlen (string_var): to compute the length of the string, not counting null character. 2. strcpy (dst_string, src_string): to copy a source string into destination string 3. int strcmp(str1, str2): to compare str1 with str2 4. strcat(dst_string, src_string): to append copy of the source string at the end of destination string Here, dst_string = destination string src_string = source string
  翻译: