SlideShare a Scribd company logo
1 of 13
Strings
String library functions
Nishma jagadish 1
String library functions
Strlen()
Strcmp()
Strcpy()
Strcat()
Strncpy()
Strncat()
Strncmp()
Strchr()
Strrchr()
Strstr()
Nishma jagadish 2
Strlen()
Size_t strlen (char const *string);
Eg:
main()
{
Int l;
Char str[20];
Str[]=“nishma”;
L=strlen (str);
Printf(“length = %d”,l);
}
o/p : length=6
Nishma jagadish 3
Strcmp()
int strcmp (const char *str1, const char *str2);
Eg:
main()
{
Int l;
Char str1[20] , str2[20];
Str1[]=“new”;
Str2[]=“new”;
L=strcmp (str1,str2);
Printf(“%d”,l);
}
o/p : 0
If s1<s2 o/p < 0
If s1==s2 o/p == 0
If s1>s2 o/p > 0
Nishma jagadish 4
Strcpy()
Char *strcpy (char *str1 , const char str2);
Eg:
main()
{
Char str1[20], str2[20];
Str1[]=“newyear”;
Str2[]=“York”;
strcpy (str1, str2);
Printf(“str1=%s, str2=%s”,str1,str2);
}
o/p :
Str1=“York”
Str2=“York”
Source
Dest
strcpy (str1, str2);
strcpy (str1, “York”);
strcpy (“new”, str2);
strcpy (“new”, “York”);
Nishma jagadish 5
Strcat()
char *strcat (char *str1, const char *str2);
Eg:
main()
{
Char str1[20] , str2[20];
Str1[]=“new”;
Str2[]=“york”;
strcat (str1,str2);
Printf(“str1=%s, str2=%s”,str1,str2);
}
o/p :
Str1=“newyork”
Str2=“York”
Nishma jagadish 6
Strncpy()
Char *strncpy (char *str1 , const char str2 , size_t n);
Eg:
main()
{
Int n=6;
Char str1[20], str2[20];
Str1[]=“department”;
Str2[]=household”;
strncpy (str1, str2,n);
Printf(“str1=%s, str2=%s”,str1,str2);
}
o/p :
Str1=“househment”
Str2=“household”
Source
Dest
strncpy (str1, str2,n);
strncpy (str1, “York”,n);
strncpy (“new”, str2,n);
strncpy (“new”, “York”,n);
Nishma jagadish 7
Strncat()
char *strncat (char *str1, const char *str2, size_t n);
Eg:
main()
{
Int n =6;
Char str1[20] , str2[20];
Str1[]=“department”;
Str2[]=“household”;
strncat (str1,str2,n);
Printf(“str1=%s, str2=%s”,str1,str2);
}
o/p :
Str1=“departmenthouseh”
Str2=“household”
Nishma jagadish 8
Strncmp()
int strncmp (const char *str1, const char *str2, size_t n);
Eg:
main()
{
Int l,n=4;
Char str1[20] , str2[20];
Str1[]=“newyear”;
Str2[]=“newyork”;
L=strncmp (str1,str2,n);
Printf(“%d”,l);
}
o/p :
If n=4, l==0
If n>4, and length of str1<str2, l is negative
If n>4, and length of str1<str2, l is positive
If s1<s2 o/p < 0
If s1==s2 o/p == 0
If s1>s2 o/p > 0
Nishma jagadish 9
Strchr()
char *strchr (const char *str , int ch);
Eg:
main()
{
Char str[20],*p;
Str[]=“department”;
P=strchr (str1, ‘e’);
Printf(“p=%s”,p);
}
o/p :
P = epartment
If the char is not present it returns null
First occurance(left most)
Nishma jagadish 10
Strrchr()
char *strrchr(const char *str , int ch);
Eg:
main()
{
Char str[20],*p;
Str[]=“department”;
P=strrchr (str, ‘e’);
Printf(“p=%s”,p);
}
o/p :
P = ent
If the char is not present it returns null
Last occurance(right most)
Nishma jagadish 11
Strstr()
char *strstr (const *s1 , const char *s2);
Eg:
main()
{
Char str1[20], str2[20];
Str1[]=“destination block”;
Str2[]=“nation”;
P=strstr (str1, str2);
Printf(“str1=%s , str2=%s”,str1,str2);
}
o/p :
Str1=nation block
Str2=nation
If str2 is station this string is not
present in str1 hence returns a
null
Used to locate the first
occurrence of a substring
in another string
Nishma jagadish 12
Thank you
Nishma jagadish 13

More Related Content

Similar to Strings library functions (20)

c programming
c programmingc programming
c programming
 
Strings part2
Strings part2Strings part2
Strings part2
 
Unitii string
Unitii stringUnitii string
Unitii string
 
Team 1
Team 1Team 1
Team 1
 
Strings in Python
Strings in PythonStrings in Python
Strings in Python
 
strings
stringsstrings
strings
 
Vcs29
Vcs29Vcs29
Vcs29
 
Strings
StringsStrings
Strings
 
Strings
StringsStrings
Strings
 
Strings
StringsStrings
Strings
 
Lecture 1 string functions
Lecture 1  string functionsLecture 1  string functions
Lecture 1 string functions
 
CP-STRING (1).ppt
CP-STRING (1).pptCP-STRING (1).ppt
CP-STRING (1).ppt
 
CP-STRING.ppt
CP-STRING.pptCP-STRING.ppt
CP-STRING.ppt
 
CP-STRING.ppt
CP-STRING.pptCP-STRING.ppt
CP-STRING.ppt
 
String notes
String notesString notes
String notes
 
introduction to strings in c programming
introduction to strings in c programmingintroduction to strings in c programming
introduction to strings in c programming
 
Module-2_Strings concepts in c programming
Module-2_Strings concepts in c programmingModule-2_Strings concepts in c programming
Module-2_Strings concepts in c programming
 
14 strings
14 strings14 strings
14 strings
 
manipulation of Strings+PPT.pptx
manipulation of Strings+PPT.pptxmanipulation of Strings+PPT.pptx
manipulation of Strings+PPT.pptx
 
Python programming : Strings
Python programming : StringsPython programming : Strings
Python programming : Strings
 

Recently uploaded

2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptxMaritesTamaniVerdade
 
How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17Celine George
 
Unit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptxUnit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptxVishalSingh1417
 
PROCESS RECORDING FORMAT.docx
PROCESS      RECORDING        FORMAT.docxPROCESS      RECORDING        FORMAT.docx
PROCESS RECORDING FORMAT.docxPoojaSen20
 
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptxSKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptxAmanpreet Kaur
 
Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)Jisc
 
General Principles of Intellectual Property: Concepts of Intellectual Proper...
General Principles of Intellectual Property: Concepts of Intellectual  Proper...General Principles of Intellectual Property: Concepts of Intellectual  Proper...
General Principles of Intellectual Property: Concepts of Intellectual Proper...Poonam Aher Patil
 
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...Nguyen Thanh Tu Collection
 
ICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxAreebaZafar22
 
Making communications land - Are they received and understood as intended? we...
Making communications land - Are they received and understood as intended? we...Making communications land - Are they received and understood as intended? we...
Making communications land - Are they received and understood as intended? we...Association for Project Management
 
Food safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdfFood safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdfSherif Taha
 
Application orientated numerical on hev.ppt
Application orientated numerical on hev.pptApplication orientated numerical on hev.ppt
Application orientated numerical on hev.pptRamjanShidvankar
 
Seal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptxSeal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptxnegromaestrong
 
The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxheathfieldcps1
 
Third Battle of Panipat detailed notes.pptx
Third Battle of Panipat detailed notes.pptxThird Battle of Panipat detailed notes.pptx
Third Battle of Panipat detailed notes.pptxAmita Gupta
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdfQucHHunhnh
 
ComPTIA Overview | Comptia Security+ Book SY0-701
ComPTIA Overview | Comptia Security+ Book SY0-701ComPTIA Overview | Comptia Security+ Book SY0-701
ComPTIA Overview | Comptia Security+ Book SY0-701bronxfugly43
 
ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.MaryamAhmad92
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfAdmir Softic
 

Recently uploaded (20)

2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
 
How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17
 
Unit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptxUnit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptx
 
PROCESS RECORDING FORMAT.docx
PROCESS      RECORDING        FORMAT.docxPROCESS      RECORDING        FORMAT.docx
PROCESS RECORDING FORMAT.docx
 
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptxSKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
 
Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)
 
General Principles of Intellectual Property: Concepts of Intellectual Proper...
General Principles of Intellectual Property: Concepts of Intellectual  Proper...General Principles of Intellectual Property: Concepts of Intellectual  Proper...
General Principles of Intellectual Property: Concepts of Intellectual Proper...
 
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
 
ICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptx
 
Making communications land - Are they received and understood as intended? we...
Making communications land - Are they received and understood as intended? we...Making communications land - Are they received and understood as intended? we...
Making communications land - Are they received and understood as intended? we...
 
Food safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdfFood safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdf
 
Application orientated numerical on hev.ppt
Application orientated numerical on hev.pptApplication orientated numerical on hev.ppt
Application orientated numerical on hev.ppt
 
Seal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptxSeal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptx
 
The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptx
 
Third Battle of Panipat detailed notes.pptx
Third Battle of Panipat detailed notes.pptxThird Battle of Panipat detailed notes.pptx
Third Battle of Panipat detailed notes.pptx
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdf
 
Asian American Pacific Islander Month DDSD 2024.pptx
Asian American Pacific Islander Month DDSD 2024.pptxAsian American Pacific Islander Month DDSD 2024.pptx
Asian American Pacific Islander Month DDSD 2024.pptx
 
ComPTIA Overview | Comptia Security+ Book SY0-701
ComPTIA Overview | Comptia Security+ Book SY0-701ComPTIA Overview | Comptia Security+ Book SY0-701
ComPTIA Overview | Comptia Security+ Book SY0-701
 
ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdf
 

Strings library functions

  • 3. Strlen() Size_t strlen (char const *string); Eg: main() { Int l; Char str[20]; Str[]=“nishma”; L=strlen (str); Printf(“length = %d”,l); } o/p : length=6 Nishma jagadish 3
  • 4. Strcmp() int strcmp (const char *str1, const char *str2); Eg: main() { Int l; Char str1[20] , str2[20]; Str1[]=“new”; Str2[]=“new”; L=strcmp (str1,str2); Printf(“%d”,l); } o/p : 0 If s1<s2 o/p < 0 If s1==s2 o/p == 0 If s1>s2 o/p > 0 Nishma jagadish 4
  • 5. Strcpy() Char *strcpy (char *str1 , const char str2); Eg: main() { Char str1[20], str2[20]; Str1[]=“newyear”; Str2[]=“York”; strcpy (str1, str2); Printf(“str1=%s, str2=%s”,str1,str2); } o/p : Str1=“York” Str2=“York” Source Dest strcpy (str1, str2); strcpy (str1, “York”); strcpy (“new”, str2); strcpy (“new”, “York”); Nishma jagadish 5
  • 6. Strcat() char *strcat (char *str1, const char *str2); Eg: main() { Char str1[20] , str2[20]; Str1[]=“new”; Str2[]=“york”; strcat (str1,str2); Printf(“str1=%s, str2=%s”,str1,str2); } o/p : Str1=“newyork” Str2=“York” Nishma jagadish 6
  • 7. Strncpy() Char *strncpy (char *str1 , const char str2 , size_t n); Eg: main() { Int n=6; Char str1[20], str2[20]; Str1[]=“department”; Str2[]=household”; strncpy (str1, str2,n); Printf(“str1=%s, str2=%s”,str1,str2); } o/p : Str1=“househment” Str2=“household” Source Dest strncpy (str1, str2,n); strncpy (str1, “York”,n); strncpy (“new”, str2,n); strncpy (“new”, “York”,n); Nishma jagadish 7
  • 8. Strncat() char *strncat (char *str1, const char *str2, size_t n); Eg: main() { Int n =6; Char str1[20] , str2[20]; Str1[]=“department”; Str2[]=“household”; strncat (str1,str2,n); Printf(“str1=%s, str2=%s”,str1,str2); } o/p : Str1=“departmenthouseh” Str2=“household” Nishma jagadish 8
  • 9. Strncmp() int strncmp (const char *str1, const char *str2, size_t n); Eg: main() { Int l,n=4; Char str1[20] , str2[20]; Str1[]=“newyear”; Str2[]=“newyork”; L=strncmp (str1,str2,n); Printf(“%d”,l); } o/p : If n=4, l==0 If n>4, and length of str1<str2, l is negative If n>4, and length of str1<str2, l is positive If s1<s2 o/p < 0 If s1==s2 o/p == 0 If s1>s2 o/p > 0 Nishma jagadish 9
  • 10. Strchr() char *strchr (const char *str , int ch); Eg: main() { Char str[20],*p; Str[]=“department”; P=strchr (str1, ‘e’); Printf(“p=%s”,p); } o/p : P = epartment If the char is not present it returns null First occurance(left most) Nishma jagadish 10
  • 11. Strrchr() char *strrchr(const char *str , int ch); Eg: main() { Char str[20],*p; Str[]=“department”; P=strrchr (str, ‘e’); Printf(“p=%s”,p); } o/p : P = ent If the char is not present it returns null Last occurance(right most) Nishma jagadish 11
  • 12. Strstr() char *strstr (const *s1 , const char *s2); Eg: main() { Char str1[20], str2[20]; Str1[]=“destination block”; Str2[]=“nation”; P=strstr (str1, str2); Printf(“str1=%s , str2=%s”,str1,str2); } o/p : Str1=nation block Str2=nation If str2 is station this string is not present in str1 hence returns a null Used to locate the first occurrence of a substring in another string Nishma jagadish 12