SlideShare a Scribd company logo
Declaration
• A string variable is declared as an array of characters.
Syntax:
char string_name[size];
e.g. char s[5];
• When the compiler assigns a character string to a
character array, it automatically supplies a null character
(‘0’) at the end of the string
VIIT, Pune 1
Initialization
Initialization Syntax:
char myString [] = { 'H','A','E','S', 'L', 'E', 'R', '0' } ;
char myString[13] = “Initial value”
char myString[] = “Initial value”;
0 = null character
Note: that ‘0’ and ‘0’ are not same.
• When we initialize a character array by listing its elements, the null
terminator or the size of the array must be provided explicitly.
• When declaring a string don’t forget to leave a space for the null
character which is also known as the string terminator character
because it is only way the functions that work with a string can know
where the string ends.
n i t i a l v a l u e ? ? …
I 0
Compilation time
initialization
VIIT, Pune 2
Differences Between Strings and Character
Arrays
VIIT, Pune 3
• Memory for strings must be allocated before the string can be
used.
• A string literal is enclosed in double quotes
VIIT, Pune 4
Reading String from terminal
• Input function scanf can be used with %s format specification to
read in a string of characters.
• Example: char address[10]; scanf(“%s”, address);
• The scanf function automatically terminates the string that is read
with a null character.
• %ws format specification can be used for reading a specified
number of characters from the input string.
• scanf with %s or %ws can ready only strings without whitespaces.
• C supports a format specification known as the edit set conversion
code %[..] that can be used to read a line containing a variety of
characters, including whitespaces.
• Example:
char line[80];
scanf(“%[^n]”,line);
VIIT, Pune 5
Library functions
• There are various string handling functions define in
string.h some of them are:
VIIT, Pune 6
strlen()
• In C, strlen() function calculates the length of string.
• It takes only one argument, i.e, string name.
Syntax:
temp_variable = strlen(string_name);
• Function strlen() returns the value of type integer.
VIIT, Pune 7
strcpy()
• Function strcpy() copies the content of one string to the
content of another string.
• Syntax of strcpy()
strcpy(destination,source);
VIIT, Pune 8
strcat()
• concatenates(joins) two strings.
• resultant string is stored in the first string
specified in the argument.
Syntax of strcat()
strcat(first_string,second_string);
VIIT, Pune 9
strcmp()
• compares two string and returns value 0, if the two strings are
equal.
Syntax of strcmp()
temp_varaible=strcmp(string1,string2);
VIIT, Pune 10
Basic Algorithms and Array along with Structure.pptx
strlwr()
• function converts all the uppercase characters in that string to
lowercase characters.
• The resultant from strlwr() is stored in the same string.
Syntax of strlwr():-
strlwr(string_name);
VIIT, Pune 12
strupr()
• function converts all the lowercase characters in that string to
uppercase characters.
• The resultant from strupr() is stored in the same string.
Syntax of strupr()
strupr(string_name);
VIIT, Pune 13
Structure in C
– Introduction to structure
• Definition
• declaration of structure, declaration of structure variables
• initialization,
• accessing members of structure
• Array of structures
Vishwakarma Institute of Information
Technology
14
What is structure
• Structure is user defined data type which allows to combine
data items of different kinds
• Structures are used to represent a record
• For example to keep track of books in a library, following
attributes about each book has to maintained−
– Book ID (Data Type – Int)
– Title (Data Type – Char)
– Author (Data Type – Char)
– Publication (Data Type – Char)
– Price (Data Type – Float)
Vishwakarma Institute of Information
Technology
15
Ad

More Related Content

Similar to Basic Algorithms and Array along with Structure.pptx (20)

Strings in programming tutorial.
Strings  in programming tutorial.Strings  in programming tutorial.
Strings in programming tutorial.
Samsil Arefin
 
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-150319180934-conversion-gate01.pdf
strings-150319180934-conversion-gate01.pdfstrings-150319180934-conversion-gate01.pdf
strings-150319180934-conversion-gate01.pdf
HEMAHEMS5
 
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
 
Strings
StringsStrings
Strings
Imad Ali
 
Strings in C
Strings in CStrings in C
Strings in C
Kamal Acharya
 
CPSTRINGSARGAVISTRINGS.PPT
CPSTRINGSARGAVISTRINGS.PPTCPSTRINGSARGAVISTRINGS.PPT
CPSTRINGSARGAVISTRINGS.PPT
Sasideepa
 
BHARGAVISTRINGS.PPT
BHARGAVISTRINGS.PPTBHARGAVISTRINGS.PPT
BHARGAVISTRINGS.PPT
Sasideepa
 
string function with example...................
string function with example...................string function with example...................
string function with example...................
NishantsrivastavaV
 
Lesson in Strings for C Programming Lessons
Lesson in Strings for C Programming LessonsLesson in Strings for C Programming Lessons
Lesson in Strings for C Programming Lessons
JamesChristianGadian
 
unit-5 String Math Date Time AI presentation
unit-5 String Math Date Time AI presentationunit-5 String Math Date Time AI presentation
unit-5 String Math Date Time AI presentation
MukeshTheLioner
 
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
 
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
 
characters_strings.pdf
characters_strings.pdfcharacters_strings.pdf
characters_strings.pdf
HoPeTaylor7
 
String notes
String notesString notes
String notes
Prasadu Peddi
 
Team 1
Team 1Team 1
Team 1
Sathasivam Rangasamy
 
Operation on string presentation
Operation on string presentationOperation on string presentation
Operation on string presentation
Aliul Kadir Akib
 
C Programming Unit-3
C Programming Unit-3C Programming Unit-3
C Programming Unit-3
Vikram Nandini
 
Strings in programming tutorial.
Strings  in programming tutorial.Strings  in programming tutorial.
Strings in programming tutorial.
Samsil Arefin
 
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-150319180934-conversion-gate01.pdf
strings-150319180934-conversion-gate01.pdfstrings-150319180934-conversion-gate01.pdf
strings-150319180934-conversion-gate01.pdf
HEMAHEMS5
 
CPSTRINGSARGAVISTRINGS.PPT
CPSTRINGSARGAVISTRINGS.PPTCPSTRINGSARGAVISTRINGS.PPT
CPSTRINGSARGAVISTRINGS.PPT
Sasideepa
 
BHARGAVISTRINGS.PPT
BHARGAVISTRINGS.PPTBHARGAVISTRINGS.PPT
BHARGAVISTRINGS.PPT
Sasideepa
 
string function with example...................
string function with example...................string function with example...................
string function with example...................
NishantsrivastavaV
 
Lesson in Strings for C Programming Lessons
Lesson in Strings for C Programming LessonsLesson in Strings for C Programming Lessons
Lesson in Strings for C Programming Lessons
JamesChristianGadian
 
unit-5 String Math Date Time AI presentation
unit-5 String Math Date Time AI presentationunit-5 String Math Date Time AI presentation
unit-5 String Math Date Time AI presentation
MukeshTheLioner
 
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
 
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
 
characters_strings.pdf
characters_strings.pdfcharacters_strings.pdf
characters_strings.pdf
HoPeTaylor7
 
Operation on string presentation
Operation on string presentationOperation on string presentation
Operation on string presentation
Aliul Kadir Akib
 

More from MrNikhilMohanShinde (16)

0708_conduction_convection_radiation.ppt
0708_conduction_convection_radiation.ppt0708_conduction_convection_radiation.ppt
0708_conduction_convection_radiation.ppt
MrNikhilMohanShinde
 
conduction-convection-radiation-powerpoint.ppt
conduction-convection-radiation-powerpoint.pptconduction-convection-radiation-powerpoint.ppt
conduction-convection-radiation-powerpoint.ppt
MrNikhilMohanShinde
 
Heat Transfer_modes of heat trasnfer.ppt
Heat Transfer_modes of heat trasnfer.pptHeat Transfer_modes of heat trasnfer.ppt
Heat Transfer_modes of heat trasnfer.ppt
MrNikhilMohanShinde
 
Types of Column loading conditions and Design.ppt
Types of Column loading conditions and Design.pptTypes of Column loading conditions and Design.ppt
Types of Column loading conditions and Design.ppt
MrNikhilMohanShinde
 
SOM Shear Force Bending Moment Diagram.ppt
SOM Shear Force Bending Moment Diagram.pptSOM Shear Force Bending Moment Diagram.ppt
SOM Shear Force Bending Moment Diagram.ppt
MrNikhilMohanShinde
 
EVs motor introdu101 - 11-13-09(web).ppt
EVs motor introdu101 - 11-13-09(web).pptEVs motor introdu101 - 11-13-09(web).ppt
EVs motor introdu101 - 11-13-09(web).ppt
MrNikhilMohanShinde
 
Unit II.pptx failure mode and effects analysis
Unit II.pptx failure mode and effects analysisUnit II.pptx failure mode and effects analysis
Unit II.pptx failure mode and effects analysis
MrNikhilMohanShinde
 
Introduction to Array & Structure & Basic Algorithms.pptx
Introduction to Array & Structure & Basic Algorithms.pptxIntroduction to Array & Structure & Basic Algorithms.pptx
Introduction to Array & Structure & Basic Algorithms.pptx
MrNikhilMohanShinde
 
Basic Concepts of the presentations.pptx
Basic Concepts of the presentations.pptxBasic Concepts of the presentations.pptx
Basic Concepts of the presentations.pptx
MrNikhilMohanShinde
 
ultimate electricity presentation for motor.ppt
ultimate electricity presentation for motor.pptultimate electricity presentation for motor.ppt
ultimate electricity presentation for motor.ppt
MrNikhilMohanShinde
 
Machine element Drawing, Machine drawing.pptx
Machine element Drawing, Machine drawing.pptxMachine element Drawing, Machine drawing.pptx
Machine element Drawing, Machine drawing.pptx
MrNikhilMohanShinde
 
Mechanical Fasteners and Joining Methods
Mechanical Fasteners and Joining MethodsMechanical Fasteners and Joining Methods
Mechanical Fasteners and Joining Methods
MrNikhilMohanShinde
 
Fastners Final.pptx
Fastners Final.pptxFastners Final.pptx
Fastners Final.pptx
MrNikhilMohanShinde
 
Inheritance, Polymorphism, and Virtual Functions.pptx
Inheritance, Polymorphism, and Virtual Functions.pptxInheritance, Polymorphism, and Virtual Functions.pptx
Inheritance, Polymorphism, and Virtual Functions.pptx
MrNikhilMohanShinde
 
Chapter-01-Components of a Computer system (1).pptx
Chapter-01-Components of a Computer system (1).pptxChapter-01-Components of a Computer system (1).pptx
Chapter-01-Components of a Computer system (1).pptx
MrNikhilMohanShinde
 
Unit-I - Introduction to Computer Fundamentals-AWI-.pptx
Unit-I - Introduction to Computer Fundamentals-AWI-.pptxUnit-I - Introduction to Computer Fundamentals-AWI-.pptx
Unit-I - Introduction to Computer Fundamentals-AWI-.pptx
MrNikhilMohanShinde
 
0708_conduction_convection_radiation.ppt
0708_conduction_convection_radiation.ppt0708_conduction_convection_radiation.ppt
0708_conduction_convection_radiation.ppt
MrNikhilMohanShinde
 
conduction-convection-radiation-powerpoint.ppt
conduction-convection-radiation-powerpoint.pptconduction-convection-radiation-powerpoint.ppt
conduction-convection-radiation-powerpoint.ppt
MrNikhilMohanShinde
 
Heat Transfer_modes of heat trasnfer.ppt
Heat Transfer_modes of heat trasnfer.pptHeat Transfer_modes of heat trasnfer.ppt
Heat Transfer_modes of heat trasnfer.ppt
MrNikhilMohanShinde
 
Types of Column loading conditions and Design.ppt
Types of Column loading conditions and Design.pptTypes of Column loading conditions and Design.ppt
Types of Column loading conditions and Design.ppt
MrNikhilMohanShinde
 
SOM Shear Force Bending Moment Diagram.ppt
SOM Shear Force Bending Moment Diagram.pptSOM Shear Force Bending Moment Diagram.ppt
SOM Shear Force Bending Moment Diagram.ppt
MrNikhilMohanShinde
 
EVs motor introdu101 - 11-13-09(web).ppt
EVs motor introdu101 - 11-13-09(web).pptEVs motor introdu101 - 11-13-09(web).ppt
EVs motor introdu101 - 11-13-09(web).ppt
MrNikhilMohanShinde
 
Unit II.pptx failure mode and effects analysis
Unit II.pptx failure mode and effects analysisUnit II.pptx failure mode and effects analysis
Unit II.pptx failure mode and effects analysis
MrNikhilMohanShinde
 
Introduction to Array & Structure & Basic Algorithms.pptx
Introduction to Array & Structure & Basic Algorithms.pptxIntroduction to Array & Structure & Basic Algorithms.pptx
Introduction to Array & Structure & Basic Algorithms.pptx
MrNikhilMohanShinde
 
Basic Concepts of the presentations.pptx
Basic Concepts of the presentations.pptxBasic Concepts of the presentations.pptx
Basic Concepts of the presentations.pptx
MrNikhilMohanShinde
 
ultimate electricity presentation for motor.ppt
ultimate electricity presentation for motor.pptultimate electricity presentation for motor.ppt
ultimate electricity presentation for motor.ppt
MrNikhilMohanShinde
 
Machine element Drawing, Machine drawing.pptx
Machine element Drawing, Machine drawing.pptxMachine element Drawing, Machine drawing.pptx
Machine element Drawing, Machine drawing.pptx
MrNikhilMohanShinde
 
Mechanical Fasteners and Joining Methods
Mechanical Fasteners and Joining MethodsMechanical Fasteners and Joining Methods
Mechanical Fasteners and Joining Methods
MrNikhilMohanShinde
 
Inheritance, Polymorphism, and Virtual Functions.pptx
Inheritance, Polymorphism, and Virtual Functions.pptxInheritance, Polymorphism, and Virtual Functions.pptx
Inheritance, Polymorphism, and Virtual Functions.pptx
MrNikhilMohanShinde
 
Chapter-01-Components of a Computer system (1).pptx
Chapter-01-Components of a Computer system (1).pptxChapter-01-Components of a Computer system (1).pptx
Chapter-01-Components of a Computer system (1).pptx
MrNikhilMohanShinde
 
Unit-I - Introduction to Computer Fundamentals-AWI-.pptx
Unit-I - Introduction to Computer Fundamentals-AWI-.pptxUnit-I - Introduction to Computer Fundamentals-AWI-.pptx
Unit-I - Introduction to Computer Fundamentals-AWI-.pptx
MrNikhilMohanShinde
 
Ad

Recently uploaded (20)

Kasdorf "Accessibility Essentials: A 2025 NISO Training Series, Session 5, Ac...
Kasdorf "Accessibility Essentials: A 2025 NISO Training Series, Session 5, Ac...Kasdorf "Accessibility Essentials: A 2025 NISO Training Series, Session 5, Ac...
Kasdorf "Accessibility Essentials: A 2025 NISO Training Series, Session 5, Ac...
National Information Standards Organization (NISO)
 
Real GitHub Copilot Exam Dumps for Success
Real GitHub Copilot Exam Dumps for SuccessReal GitHub Copilot Exam Dumps for Success
Real GitHub Copilot Exam Dumps for Success
Mark Soia
 
Ranking_Felicidade_2024_com_Educacao_Marketing Educacional_V2.pdf
Ranking_Felicidade_2024_com_Educacao_Marketing Educacional_V2.pdfRanking_Felicidade_2024_com_Educacao_Marketing Educacional_V2.pdf
Ranking_Felicidade_2024_com_Educacao_Marketing Educacional_V2.pdf
Rafael Villas B
 
Presentation on Tourism Product Development By Md Shaifullar Rabbi
Presentation on Tourism Product Development By Md Shaifullar RabbiPresentation on Tourism Product Development By Md Shaifullar Rabbi
Presentation on Tourism Product Development By Md Shaifullar Rabbi
Md Shaifullar Rabbi
 
apa-style-referencing-visual-guide-2025.pdf
apa-style-referencing-visual-guide-2025.pdfapa-style-referencing-visual-guide-2025.pdf
apa-style-referencing-visual-guide-2025.pdf
Ishika Ghosh
 
K12 Tableau Tuesday - Algebra Equity and Access in Atlanta Public Schools
K12 Tableau Tuesday  - Algebra Equity and Access in Atlanta Public SchoolsK12 Tableau Tuesday  - Algebra Equity and Access in Atlanta Public Schools
K12 Tableau Tuesday - Algebra Equity and Access in Atlanta Public Schools
dogden2
 
SCI BIZ TECH QUIZ (OPEN) PRELIMS XTASY 2025.pptx
SCI BIZ TECH QUIZ (OPEN) PRELIMS XTASY 2025.pptxSCI BIZ TECH QUIZ (OPEN) PRELIMS XTASY 2025.pptx
SCI BIZ TECH QUIZ (OPEN) PRELIMS XTASY 2025.pptx
Ronisha Das
 
Presentation of the MIPLM subject matter expert Erdem Kaya
Presentation of the MIPLM subject matter expert Erdem KayaPresentation of the MIPLM subject matter expert Erdem Kaya
Presentation of the MIPLM subject matter expert Erdem Kaya
MIPLM
 
How to Create A Todo List In Todo of Odoo 18
How to Create A Todo List In Todo of Odoo 18How to Create A Todo List In Todo of Odoo 18
How to Create A Todo List In Todo of Odoo 18
Celine George
 
Herbs Used in Cosmetic Formulations .pptx
Herbs Used in Cosmetic Formulations .pptxHerbs Used in Cosmetic Formulations .pptx
Herbs Used in Cosmetic Formulations .pptx
RAJU THENGE
 
Metamorphosis: Life's Transformative Journey
Metamorphosis: Life's Transformative JourneyMetamorphosis: Life's Transformative Journey
Metamorphosis: Life's Transformative Journey
Arshad Shaikh
 
"Basics of Heterocyclic Compounds and Their Naming Rules"
"Basics of Heterocyclic Compounds and Their Naming Rules""Basics of Heterocyclic Compounds and Their Naming Rules"
"Basics of Heterocyclic Compounds and Their Naming Rules"
rupalinirmalbpharm
 
03#UNTAGGED. Generosity in architecture.
03#UNTAGGED. Generosity in architecture.03#UNTAGGED. Generosity in architecture.
03#UNTAGGED. Generosity in architecture.
MCH
 
APM Midlands Region April 2025 Sacha Hind Circulated.pdf
APM Midlands Region April 2025 Sacha Hind Circulated.pdfAPM Midlands Region April 2025 Sacha Hind Circulated.pdf
APM Midlands Region April 2025 Sacha Hind Circulated.pdf
Association for Project Management
 
Geography Sem II Unit 1C Correlation of Geography with other school subjects
Geography Sem II Unit 1C Correlation of Geography with other school subjectsGeography Sem II Unit 1C Correlation of Geography with other school subjects
Geography Sem II Unit 1C Correlation of Geography with other school subjects
ProfDrShaikhImran
 
How to manage Multiple Warehouses for multiple floors in odoo point of sale
How to manage Multiple Warehouses for multiple floors in odoo point of saleHow to manage Multiple Warehouses for multiple floors in odoo point of sale
How to manage Multiple Warehouses for multiple floors in odoo point of sale
Celine George
 
How to Manage Purchase Alternatives in Odoo 18
How to Manage Purchase Alternatives in Odoo 18How to Manage Purchase Alternatives in Odoo 18
How to Manage Purchase Alternatives in Odoo 18
Celine George
 
YSPH VMOC Special Report - Measles Outbreak Southwest US 5-3-2025.pptx
YSPH VMOC Special Report - Measles Outbreak  Southwest US 5-3-2025.pptxYSPH VMOC Special Report - Measles Outbreak  Southwest US 5-3-2025.pptx
YSPH VMOC Special Report - Measles Outbreak Southwest US 5-3-2025.pptx
Yale School of Public Health - The Virtual Medical Operations Center (VMOC)
 
Biophysics Chapter 3 Methods of Studying Macromolecules.pdf
Biophysics Chapter 3 Methods of Studying Macromolecules.pdfBiophysics Chapter 3 Methods of Studying Macromolecules.pdf
Biophysics Chapter 3 Methods of Studying Macromolecules.pdf
PKLI-Institute of Nursing and Allied Health Sciences Lahore , Pakistan.
 
dynastic art of the Pallava dynasty south India
dynastic art of the Pallava dynasty south Indiadynastic art of the Pallava dynasty south India
dynastic art of the Pallava dynasty south India
PrachiSontakke5
 
Real GitHub Copilot Exam Dumps for Success
Real GitHub Copilot Exam Dumps for SuccessReal GitHub Copilot Exam Dumps for Success
Real GitHub Copilot Exam Dumps for Success
Mark Soia
 
Ranking_Felicidade_2024_com_Educacao_Marketing Educacional_V2.pdf
Ranking_Felicidade_2024_com_Educacao_Marketing Educacional_V2.pdfRanking_Felicidade_2024_com_Educacao_Marketing Educacional_V2.pdf
Ranking_Felicidade_2024_com_Educacao_Marketing Educacional_V2.pdf
Rafael Villas B
 
Presentation on Tourism Product Development By Md Shaifullar Rabbi
Presentation on Tourism Product Development By Md Shaifullar RabbiPresentation on Tourism Product Development By Md Shaifullar Rabbi
Presentation on Tourism Product Development By Md Shaifullar Rabbi
Md Shaifullar Rabbi
 
apa-style-referencing-visual-guide-2025.pdf
apa-style-referencing-visual-guide-2025.pdfapa-style-referencing-visual-guide-2025.pdf
apa-style-referencing-visual-guide-2025.pdf
Ishika Ghosh
 
K12 Tableau Tuesday - Algebra Equity and Access in Atlanta Public Schools
K12 Tableau Tuesday  - Algebra Equity and Access in Atlanta Public SchoolsK12 Tableau Tuesday  - Algebra Equity and Access in Atlanta Public Schools
K12 Tableau Tuesday - Algebra Equity and Access in Atlanta Public Schools
dogden2
 
SCI BIZ TECH QUIZ (OPEN) PRELIMS XTASY 2025.pptx
SCI BIZ TECH QUIZ (OPEN) PRELIMS XTASY 2025.pptxSCI BIZ TECH QUIZ (OPEN) PRELIMS XTASY 2025.pptx
SCI BIZ TECH QUIZ (OPEN) PRELIMS XTASY 2025.pptx
Ronisha Das
 
Presentation of the MIPLM subject matter expert Erdem Kaya
Presentation of the MIPLM subject matter expert Erdem KayaPresentation of the MIPLM subject matter expert Erdem Kaya
Presentation of the MIPLM subject matter expert Erdem Kaya
MIPLM
 
How to Create A Todo List In Todo of Odoo 18
How to Create A Todo List In Todo of Odoo 18How to Create A Todo List In Todo of Odoo 18
How to Create A Todo List In Todo of Odoo 18
Celine George
 
Herbs Used in Cosmetic Formulations .pptx
Herbs Used in Cosmetic Formulations .pptxHerbs Used in Cosmetic Formulations .pptx
Herbs Used in Cosmetic Formulations .pptx
RAJU THENGE
 
Metamorphosis: Life's Transformative Journey
Metamorphosis: Life's Transformative JourneyMetamorphosis: Life's Transformative Journey
Metamorphosis: Life's Transformative Journey
Arshad Shaikh
 
"Basics of Heterocyclic Compounds and Their Naming Rules"
"Basics of Heterocyclic Compounds and Their Naming Rules""Basics of Heterocyclic Compounds and Their Naming Rules"
"Basics of Heterocyclic Compounds and Their Naming Rules"
rupalinirmalbpharm
 
03#UNTAGGED. Generosity in architecture.
03#UNTAGGED. Generosity in architecture.03#UNTAGGED. Generosity in architecture.
03#UNTAGGED. Generosity in architecture.
MCH
 
Geography Sem II Unit 1C Correlation of Geography with other school subjects
Geography Sem II Unit 1C Correlation of Geography with other school subjectsGeography Sem II Unit 1C Correlation of Geography with other school subjects
Geography Sem II Unit 1C Correlation of Geography with other school subjects
ProfDrShaikhImran
 
How to manage Multiple Warehouses for multiple floors in odoo point of sale
How to manage Multiple Warehouses for multiple floors in odoo point of saleHow to manage Multiple Warehouses for multiple floors in odoo point of sale
How to manage Multiple Warehouses for multiple floors in odoo point of sale
Celine George
 
How to Manage Purchase Alternatives in Odoo 18
How to Manage Purchase Alternatives in Odoo 18How to Manage Purchase Alternatives in Odoo 18
How to Manage Purchase Alternatives in Odoo 18
Celine George
 
dynastic art of the Pallava dynasty south India
dynastic art of the Pallava dynasty south Indiadynastic art of the Pallava dynasty south India
dynastic art of the Pallava dynasty south India
PrachiSontakke5
 
Ad

Basic Algorithms and Array along with Structure.pptx

  • 1. Declaration • A string variable is declared as an array of characters. Syntax: char string_name[size]; e.g. char s[5]; • When the compiler assigns a character string to a character array, it automatically supplies a null character (‘0’) at the end of the string VIIT, Pune 1
  • 2. Initialization Initialization Syntax: char myString [] = { 'H','A','E','S', 'L', 'E', 'R', '0' } ; char myString[13] = “Initial value” char myString[] = “Initial value”; 0 = null character Note: that ‘0’ and ‘0’ are not same. • When we initialize a character array by listing its elements, the null terminator or the size of the array must be provided explicitly. • When declaring a string don’t forget to leave a space for the null character which is also known as the string terminator character because it is only way the functions that work with a string can know where the string ends. n i t i a l v a l u e ? ? … I 0 Compilation time initialization VIIT, Pune 2
  • 3. Differences Between Strings and Character Arrays VIIT, Pune 3
  • 4. • Memory for strings must be allocated before the string can be used. • A string literal is enclosed in double quotes VIIT, Pune 4
  • 5. Reading String from terminal • Input function scanf can be used with %s format specification to read in a string of characters. • Example: char address[10]; scanf(“%s”, address); • The scanf function automatically terminates the string that is read with a null character. • %ws format specification can be used for reading a specified number of characters from the input string. • scanf with %s or %ws can ready only strings without whitespaces. • C supports a format specification known as the edit set conversion code %[..] that can be used to read a line containing a variety of characters, including whitespaces. • Example: char line[80]; scanf(“%[^n]”,line); VIIT, Pune 5
  • 6. Library functions • There are various string handling functions define in string.h some of them are: VIIT, Pune 6
  • 7. strlen() • In C, strlen() function calculates the length of string. • It takes only one argument, i.e, string name. Syntax: temp_variable = strlen(string_name); • Function strlen() returns the value of type integer. VIIT, Pune 7
  • 8. strcpy() • Function strcpy() copies the content of one string to the content of another string. • Syntax of strcpy() strcpy(destination,source); VIIT, Pune 8
  • 9. strcat() • concatenates(joins) two strings. • resultant string is stored in the first string specified in the argument. Syntax of strcat() strcat(first_string,second_string); VIIT, Pune 9
  • 10. strcmp() • compares two string and returns value 0, if the two strings are equal. Syntax of strcmp() temp_varaible=strcmp(string1,string2); VIIT, Pune 10
  • 12. strlwr() • function converts all the uppercase characters in that string to lowercase characters. • The resultant from strlwr() is stored in the same string. Syntax of strlwr():- strlwr(string_name); VIIT, Pune 12
  • 13. strupr() • function converts all the lowercase characters in that string to uppercase characters. • The resultant from strupr() is stored in the same string. Syntax of strupr() strupr(string_name); VIIT, Pune 13
  • 14. Structure in C – Introduction to structure • Definition • declaration of structure, declaration of structure variables • initialization, • accessing members of structure • Array of structures Vishwakarma Institute of Information Technology 14
  • 15. What is structure • Structure is user defined data type which allows to combine data items of different kinds • Structures are used to represent a record • For example to keep track of books in a library, following attributes about each book has to maintained− – Book ID (Data Type – Int) – Title (Data Type – Char) – Author (Data Type – Char) – Publication (Data Type – Char) – Price (Data Type – Float) Vishwakarma Institute of Information Technology 15