SlideShare a Scribd company logo
3
Most read
4
Most read
5
Most read
Strings in C Programming
By Asst. Prof. Sonali Gholve
String
predefined
functions
Strlen()
Strrev()
Strcat()Strcpy()
Strcmp()
Predefined string functions
โ€ข C Programming language provides a set of
predefined string functions called string
handling functions to work with string values.
โ€ข <string.h>
โ€“ strlen()
โ€“ strrev()
โ€“ strcat()
โ€“ strcpy()
โ€“ strcmp()
Strlen()
This function is used to calculate length of string.
#include<stdio.h>
#include<string.h>
int main()
{
char a[20]=โ€œIndiaโ€;
printf(โ€œLength of string=%dโ€, strlen(a));
return 0;
}
0 1 2 3 4 5 6 7
I n d i a 0
Output:
Length of string=5
Strrev()
This function is used to reverse the given string .
#include<stdio.h>
#include<string.h>
int main()
{
char a[20]=โ€œIndiaโ€;
Printf(โ€œstring before reversing=%sโ€,a);
printf(โ€œReverse of given string=%sโ€, strrev(a));
return 0;
}
0 1 2 3 4 5 6 7
I n d i a 0
0 1 2 3 4 5 6 7
a i d n i 0
Output:
String before reversing=India
Reverse of given string=aidni
Strcat()
This function is used to concatenates two given strings.
It concatenates source string at the end of target string.
#include<stdio.h>
#include<string.h>
int main()
{
char a[20]=โ€œHelloโ€, b[20]=โ€œPuneโ€;
printf(โ€œstring first before concatenate=%sโ€,a);
strcat(a,b);
printf(โ€œString after concatenation=%sโ€, a);
return 0;
}
0 1 2 3 4 5 6
H e l l o 0
0 1 2 3 4 5 6 7
P u n e 0
Output:
String first before concatenate =Hello
String after Concatenation=HelloPune
0 1 2 3 4 5 6 7 8 9 10
H e l l o P u n e 0
Strcpy()
This function is used to copy one string into other
character array .
#include<stdio.h>
#include<string.h>
int main()
{
char a[20]=โ€œIndiaโ€, b[20];
strcpy(b,a);
printf(โ€œContents of string second=%sโ€, b);
return 0;
}
0 1 2 3 4 5 6 7
I n d i a 0
0 1 2 3 4 5 6 7
I n d i a 0
Output:
Contents of string second=India
0 1 2 3 4 5 6 7
Strcmp()
This function is used to compare two strings.
0=> If strings are same
+ve=>ASCII of first character is greater
-ve=> ASCII of first unmatched character is less
#include<stdio.h>
#include<string.h>
int main()
{
char a[20]=โ€œANTโ€, b[20]=โ€œBALLโ€;
char c[10]=โ€œANTโ€;
int result;
result=strcmp(a,b);
printf(โ€œstrcmp(a,b)=%dnโ€, result);
result=strcmp(b,c);
printf(โ€œstrcmp(b,c)=%dnโ€, result);
return 0;
}
0 1 2 3 4 5 6 7
A N T 0
Output:
Strcmp(a,b)=-1
Strcmp(b,c)=0
0 1 2 3 4 5 6 7
B A L L 0
0 1 2 3 4 5 6 7
A N T 0

More Related Content

What's hot (20)

PPTX
Pointers in C Programming
Jasleen Kaur (Chandigarh University)
ย 
PPTX
Function in c
CGC Technical campus,Mohali
ย 
PPTX
Recursive Function
Harsh Pathak
ย 
PPTX
Data Types and Variables In C Programming
Kamal Acharya
ย 
PPTX
C language unit-1
Malikireddy Bramhananda Reddy
ย 
PPTX
Functions in Python
Shakti Singh Rathore
ย 
PDF
Stack
Zaid Shabbir
ย 
PPTX
Dynamic memory allocation in c
lavanya marichamy
ย 
PPT
Finite automata
Bipul Roy Bpl
ย 
PPTX
Stack organization
chauhankapil
ย 
PPTX
Function in C Programming
Anil Pokhrel
ย 
PPTX
Deque and its applications
Jsaddam Hussain
ย 
PPTX
Data types
Zahid Hussain
ย 
PPTX
Object Oriented Programming Using C++
Muhammad Waqas
ย 
PPT
File handling in c
David Livingston J
ย 
PPTX
Programming in c Arrays
janani thirupathi
ย 
PPTX
Function Pointer
Dr-Dipali Meher
ย 
PPT
User Defined Functions
Praveen M Jigajinni
ย 
PDF
Applications of stack
eShikshak
ย 
PPTX
Data types in c++
Venkata.Manish Reddy
ย 
Pointers in C Programming
Jasleen Kaur (Chandigarh University)
ย 
Function in c
CGC Technical campus,Mohali
ย 
Recursive Function
Harsh Pathak
ย 
Data Types and Variables In C Programming
Kamal Acharya
ย 
C language unit-1
Malikireddy Bramhananda Reddy
ย 
Functions in Python
Shakti Singh Rathore
ย 
Stack
Zaid Shabbir
ย 
Dynamic memory allocation in c
lavanya marichamy
ย 
Finite automata
Bipul Roy Bpl
ย 
Stack organization
chauhankapil
ย 
Function in C Programming
Anil Pokhrel
ย 
Deque and its applications
Jsaddam Hussain
ย 
Data types
Zahid Hussain
ย 
Object Oriented Programming Using C++
Muhammad Waqas
ย 
File handling in c
David Livingston J
ย 
Programming in c Arrays
janani thirupathi
ย 
Function Pointer
Dr-Dipali Meher
ย 
User Defined Functions
Praveen M Jigajinni
ย 
Applications of stack
eShikshak
ย 
Data types in c++
Venkata.Manish Reddy
ย 

Similar to String predefined functions in C programming (20)

PDF
Strings part2
yndaravind
ย 
PDF
Principals of Programming in CModule -5.pdfModule-4.pdf
anilcsbs
ย 
DOCX
Unitii string
Sowri Rajan
ย 
PPTX
POEPPSGNHwkejnkweoewnkenjwjewkjewoewkjewijewjk
hanumanthumanideeph6
ย 
PPTX
STRING FUNCTION - Programming in C.pptx
Indhu Periys
ย 
PPT
Strings
Mitali Chugh
ย 
PPT
14 strings
Rohit Shrivastava
ย 
PPTX
Module-2_Strings concepts in c programming
CHAITRAB29
ย 
PPT
Strings in c
vampugani
ย 
PPTX
introduction to strings in c programming
mikeymanjiro2090
ย 
PPTX
Strings CPU GTU
Maharshi Dave
ย 
PPTX
Character Arrays and strings in c language
mallikavin
ย 
PDF
[ITP - Lecture 17] Strings in C/C++
Muhammad Hammad Waseem
ย 
PPTX
Strings
Saranya saran
ย 
PPTX
Presentation more c_programmingcharacter_and_string_handling_
KarthicaMarasamy
ย 
PPT
strings
teach4uin
ย 
PPTX
CSE 1102 - Lecture_7 - Strings_in_C.pptx
Salim Shadman Ankur
ย 
PDF
PROBLEM SOLVING USING A PPSC- UNIT -3.pdf
JNTUK KAKINADA
ย 
PPTX
Strings cprogramminglanguagedsasheet.pptx
hyundaitvhamari
ย 
PPTX
Computer Programming Utilities the subject of BE first year students, and thi...
jr2710
ย 
Strings part2
yndaravind
ย 
Principals of Programming in CModule -5.pdfModule-4.pdf
anilcsbs
ย 
Unitii string
Sowri Rajan
ย 
POEPPSGNHwkejnkweoewnkenjwjewkjewoewkjewijewjk
hanumanthumanideeph6
ย 
STRING FUNCTION - Programming in C.pptx
Indhu Periys
ย 
Strings
Mitali Chugh
ย 
14 strings
Rohit Shrivastava
ย 
Module-2_Strings concepts in c programming
CHAITRAB29
ย 
Strings in c
vampugani
ย 
introduction to strings in c programming
mikeymanjiro2090
ย 
Strings CPU GTU
Maharshi Dave
ย 
Character Arrays and strings in c language
mallikavin
ย 
[ITP - Lecture 17] Strings in C/C++
Muhammad Hammad Waseem
ย 
Strings
Saranya saran
ย 
Presentation more c_programmingcharacter_and_string_handling_
KarthicaMarasamy
ย 
strings
teach4uin
ย 
CSE 1102 - Lecture_7 - Strings_in_C.pptx
Salim Shadman Ankur
ย 
PROBLEM SOLVING USING A PPSC- UNIT -3.pdf
JNTUK KAKINADA
ย 
Strings cprogramminglanguagedsasheet.pptx
hyundaitvhamari
ย 
Computer Programming Utilities the subject of BE first year students, and thi...
jr2710
ย 
Ad

More from ProfSonaliGholveDoif (6)

PPTX
Searching in Artificial Intelligence for UG
ProfSonaliGholveDoif
ย 
PPTX
Artificial Intelligence Basics part 1 for UG students
ProfSonaliGholveDoif
ย 
PPTX
Introduction to Data Structure part 1
ProfSonaliGholveDoif
ย 
PPTX
Inheritance in c++theory
ProfSonaliGholveDoif
ย 
PPTX
File handling in c++
ProfSonaliGholveDoif
ย 
PPTX
Macro and Preprocessor in c programming
ProfSonaliGholveDoif
ย 
Searching in Artificial Intelligence for UG
ProfSonaliGholveDoif
ย 
Artificial Intelligence Basics part 1 for UG students
ProfSonaliGholveDoif
ย 
Introduction to Data Structure part 1
ProfSonaliGholveDoif
ย 
Inheritance in c++theory
ProfSonaliGholveDoif
ย 
File handling in c++
ProfSonaliGholveDoif
ย 
Macro and Preprocessor in c programming
ProfSonaliGholveDoif
ย 
Ad

Recently uploaded (20)

PPTX
IObit Driver Booster Pro Crack Download Latest Version
chaudhryakashoo065
ย 
PPTX
IDM Crack with Internet Download Manager 6.42 [Latest 2025]
HyperPc soft
ย 
PDF
TEASMA: A Practical Methodology for Test Adequacy Assessment of Deep Neural N...
Lionel Briand
ย 
PPTX
Android Notifications-A Guide to User-Facing Alerts in Android .pptx
Nabin Dhakal
ย 
PPTX
Quality on Autopilot: Scaling Testing in Uyuni
Oscar Barrios Torrero
ย 
PPTX
NeuroStrata: Harnessing Neuro-Symbolic Paradigms for Improved Testability and...
Ivan Ruchkin
ย 
PDF
Dealing with JSON in the relational world
Andres Almiray
ย 
PDF
Automated Test Case Repair Using Language Models
Lionel Briand
ย 
PPTX
How Can Recruitment Management Software Improve Hiring Efficiency?
HireME
ย 
PPTX
IObit Uninstaller Pro 14.3.1.8 Crack Free Download 2025
sdfger qwerty
ย 
PPTX
Introduction to web development | MERN Stack
JosephLiyon
ย 
PPTX
Wondershare Filmora Crack 14.5.18 + Key Full Download [Latest 2025]
HyperPc soft
ย 
PPTX
computer forensics encase emager app exp6 1.pptx
ssuser343e92
ย 
PDF
capitulando la keynote de GrafanaCON 2025 - Madrid
Imma Valls Bernaus
ย 
PPTX
Iobit Driver Booster Pro 12 Crack Free Download
chaudhryakashoo065
ย 
PDF
Difference Between Kubernetes and Docker .pdf
Kindlebit Solutions
ย 
PDF
AI Software Development Process, Strategies and Challenges
Net-Craft.com
ย 
PDF
Laboratory Workflows Digitalized and live in 90 days with Scifeonยดs SAPPA P...
info969686
ย 
PDF
AWS Consulting Services: Empowering Digital Transformation with Nlineaxis
Nlineaxis IT Solutions Pvt Ltd
ย 
PDF
Power BI vs Tableau vs Looker - Which BI Tool is Right for You?
MagnusMinds IT Solution LLP
ย 
IObit Driver Booster Pro Crack Download Latest Version
chaudhryakashoo065
ย 
IDM Crack with Internet Download Manager 6.42 [Latest 2025]
HyperPc soft
ย 
TEASMA: A Practical Methodology for Test Adequacy Assessment of Deep Neural N...
Lionel Briand
ย 
Android Notifications-A Guide to User-Facing Alerts in Android .pptx
Nabin Dhakal
ย 
Quality on Autopilot: Scaling Testing in Uyuni
Oscar Barrios Torrero
ย 
NeuroStrata: Harnessing Neuro-Symbolic Paradigms for Improved Testability and...
Ivan Ruchkin
ย 
Dealing with JSON in the relational world
Andres Almiray
ย 
Automated Test Case Repair Using Language Models
Lionel Briand
ย 
How Can Recruitment Management Software Improve Hiring Efficiency?
HireME
ย 
IObit Uninstaller Pro 14.3.1.8 Crack Free Download 2025
sdfger qwerty
ย 
Introduction to web development | MERN Stack
JosephLiyon
ย 
Wondershare Filmora Crack 14.5.18 + Key Full Download [Latest 2025]
HyperPc soft
ย 
computer forensics encase emager app exp6 1.pptx
ssuser343e92
ย 
capitulando la keynote de GrafanaCON 2025 - Madrid
Imma Valls Bernaus
ย 
Iobit Driver Booster Pro 12 Crack Free Download
chaudhryakashoo065
ย 
Difference Between Kubernetes and Docker .pdf
Kindlebit Solutions
ย 
AI Software Development Process, Strategies and Challenges
Net-Craft.com
ย 
Laboratory Workflows Digitalized and live in 90 days with Scifeonยดs SAPPA P...
info969686
ย 
AWS Consulting Services: Empowering Digital Transformation with Nlineaxis
Nlineaxis IT Solutions Pvt Ltd
ย 
Power BI vs Tableau vs Looker - Which BI Tool is Right for You?
MagnusMinds IT Solution LLP
ย 

String predefined functions in C programming

  • 1. Strings in C Programming By Asst. Prof. Sonali Gholve String predefined functions Strlen() Strrev() Strcat()Strcpy() Strcmp()
  • 2. Predefined string functions โ€ข C Programming language provides a set of predefined string functions called string handling functions to work with string values. โ€ข <string.h> โ€“ strlen() โ€“ strrev() โ€“ strcat() โ€“ strcpy() โ€“ strcmp()
  • 3. Strlen() This function is used to calculate length of string. #include<stdio.h> #include<string.h> int main() { char a[20]=โ€œIndiaโ€; printf(โ€œLength of string=%dโ€, strlen(a)); return 0; } 0 1 2 3 4 5 6 7 I n d i a 0 Output: Length of string=5
  • 4. Strrev() This function is used to reverse the given string . #include<stdio.h> #include<string.h> int main() { char a[20]=โ€œIndiaโ€; Printf(โ€œstring before reversing=%sโ€,a); printf(โ€œReverse of given string=%sโ€, strrev(a)); return 0; } 0 1 2 3 4 5 6 7 I n d i a 0 0 1 2 3 4 5 6 7 a i d n i 0 Output: String before reversing=India Reverse of given string=aidni
  • 5. Strcat() This function is used to concatenates two given strings. It concatenates source string at the end of target string. #include<stdio.h> #include<string.h> int main() { char a[20]=โ€œHelloโ€, b[20]=โ€œPuneโ€; printf(โ€œstring first before concatenate=%sโ€,a); strcat(a,b); printf(โ€œString after concatenation=%sโ€, a); return 0; } 0 1 2 3 4 5 6 H e l l o 0 0 1 2 3 4 5 6 7 P u n e 0 Output: String first before concatenate =Hello String after Concatenation=HelloPune 0 1 2 3 4 5 6 7 8 9 10 H e l l o P u n e 0
  • 6. Strcpy() This function is used to copy one string into other character array . #include<stdio.h> #include<string.h> int main() { char a[20]=โ€œIndiaโ€, b[20]; strcpy(b,a); printf(โ€œContents of string second=%sโ€, b); return 0; } 0 1 2 3 4 5 6 7 I n d i a 0 0 1 2 3 4 5 6 7 I n d i a 0 Output: Contents of string second=India 0 1 2 3 4 5 6 7
  • 7. Strcmp() This function is used to compare two strings. 0=> If strings are same +ve=>ASCII of first character is greater -ve=> ASCII of first unmatched character is less #include<stdio.h> #include<string.h> int main() { char a[20]=โ€œANTโ€, b[20]=โ€œBALLโ€; char c[10]=โ€œANTโ€; int result; result=strcmp(a,b); printf(โ€œstrcmp(a,b)=%dnโ€, result); result=strcmp(b,c); printf(โ€œstrcmp(b,c)=%dnโ€, result); return 0; } 0 1 2 3 4 5 6 7 A N T 0 Output: Strcmp(a,b)=-1 Strcmp(b,c)=0 0 1 2 3 4 5 6 7 B A L L 0 0 1 2 3 4 5 6 7 A N T 0