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

PPTX
Character Arrays and strings in c language
PPTX
C data types, arrays and structs
PPTX
Programming in c Arrays
PPTX
PPTX
PDF
C Programming Storage classes, Recursion
DOC
String in c
Character Arrays and strings in c language
C data types, arrays and structs
Programming in c Arrays
C Programming Storage classes, Recursion
String in c

What's hot (20)

PPT
Introduction to c programming
PPTX
C programming - String
PPTX
Array in c programming
PPTX
Looping statements in C
PPTX
Basic Input and Output
PPSX
Function in c
PPTX
Unit 2. Elements of C
PDF
Character Array and String
PPT
Strings
PDF
Command line-arguments-in-java-tutorial
PDF
Strings IN C
PPT
PHP - DataType,Variable,Constant,Operators,Array,Include and require
PPT
File handling in c
PPTX
Variables in python
PPT
constants, variables and datatypes in C
DOC
C lab-programs
PPTX
Structure in c language
PPT
Strings in c
PDF
Class and object
PDF
List , tuples, dictionaries and regular expressions in python
Introduction to c programming
C programming - String
Array in c programming
Looping statements in C
Basic Input and Output
Function in c
Unit 2. Elements of C
Character Array and String
Strings
Command line-arguments-in-java-tutorial
Strings IN C
PHP - DataType,Variable,Constant,Operators,Array,Include and require
File handling in c
Variables in python
constants, variables and datatypes in C
C lab-programs
Structure in c language
Strings in c
Class and object
List , tuples, dictionaries and regular expressions in python
Ad

Similar to String predefined functions in C programming (20)

PPTX
POEPPSGNHwkejnkweoewnkenjwjewkjewoewkjewijewjk
PPTX
Lecture 2. mte 407
PPTX
unit-5 String Math Date Time AI presentation
PPTX
programming for problem solving using C-STRINGSc
DOCX
Unitii string
PPTX
String_C.pptx
PPTX
Library functions in c++
PPTX
Module-2_Strings concepts in c programming
PPTX
UNIT 4C-Strings.pptx for c language and basic knowledge
PDF
Principals of Programming in CModule -5.pdfModule-4.pdf
PPTX
C-Arrays & Strings (computer programming).pptx
PDF
PROBLEM SOLVING USING A PPSC- UNIT -3.pdf
DOCX
Write a program to check a given number is prime or not
PPTX
Introduction about Low Level Programming using C
PPTX
Lecture 1 string functions
PPTX
Quiz On Strings
PPT
Unit 5 Foc
PPTX
Lecture 15_Strings and Dynamic Memory Allocation.pptx
PPTX
Lecture 24 PART 1.pptxkhfwraetrsytfyugiuihjojiiyutdruot8
DOCX
string , pointer
POEPPSGNHwkejnkweoewnkenjwjewkjewoewkjewijewjk
Lecture 2. mte 407
unit-5 String Math Date Time AI presentation
programming for problem solving using C-STRINGSc
Unitii string
String_C.pptx
Library functions in c++
Module-2_Strings concepts in c programming
UNIT 4C-Strings.pptx for c language and basic knowledge
Principals of Programming in CModule -5.pdfModule-4.pdf
C-Arrays & Strings (computer programming).pptx
PROBLEM SOLVING USING A PPSC- UNIT -3.pdf
Write a program to check a given number is prime or not
Introduction about Low Level Programming using C
Lecture 1 string functions
Quiz On Strings
Unit 5 Foc
Lecture 15_Strings and Dynamic Memory Allocation.pptx
Lecture 24 PART 1.pptxkhfwraetrsytfyugiuihjojiiyutdruot8
string , pointer
Ad

More from ProfSonaliGholveDoif (6)

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

Recently uploaded (20)

PDF
Claude Code: Everyone is a 10x Developer - A Comprehensive AI-Powered CLI Tool
PPTX
ai tools demonstartion for schools and inter college
PDF
System and Network Administraation Chapter 3
PPTX
ManageIQ - Sprint 268 Review - Slide Deck
PDF
Which alternative to Crystal Reports is best for small or large businesses.pdf
PPTX
ISO 45001 Occupational Health and Safety Management System
PPTX
Odoo POS Development Services by CandidRoot Solutions
PDF
Why TechBuilder is the Future of Pickup and Delivery App Development (1).pdf
PPTX
CHAPTER 2 - PM Management and IT Context
PDF
Upgrade and Innovation Strategies for SAP ERP Customers
PDF
AI in Product Development-omnex systems
PPTX
CHAPTER 12 - CYBER SECURITY AND FUTURE SKILLS (1) (1).pptx
PDF
PTS Company Brochure 2025 (1).pdf.......
PDF
T3DD25 TYPO3 Content Blocks - Deep Dive by André Kraus
PDF
Softaken Excel to vCard Converter Software.pdf
PPTX
Online Work Permit System for Fast Permit Processing
PDF
Adobe Illustrator 28.6 Crack My Vision of Vector Design
PDF
Nekopoi APK 2025 free lastest update
PPTX
VVF-Customer-Presentation2025-Ver1.9.pptx
PDF
Navsoft: AI-Powered Business Solutions & Custom Software Development
Claude Code: Everyone is a 10x Developer - A Comprehensive AI-Powered CLI Tool
ai tools demonstartion for schools and inter college
System and Network Administraation Chapter 3
ManageIQ - Sprint 268 Review - Slide Deck
Which alternative to Crystal Reports is best for small or large businesses.pdf
ISO 45001 Occupational Health and Safety Management System
Odoo POS Development Services by CandidRoot Solutions
Why TechBuilder is the Future of Pickup and Delivery App Development (1).pdf
CHAPTER 2 - PM Management and IT Context
Upgrade and Innovation Strategies for SAP ERP Customers
AI in Product Development-omnex systems
CHAPTER 12 - CYBER SECURITY AND FUTURE SKILLS (1) (1).pptx
PTS Company Brochure 2025 (1).pdf.......
T3DD25 TYPO3 Content Blocks - Deep Dive by André Kraus
Softaken Excel to vCard Converter Software.pdf
Online Work Permit System for Fast Permit Processing
Adobe Illustrator 28.6 Crack My Vision of Vector Design
Nekopoi APK 2025 free lastest update
VVF-Customer-Presentation2025-Ver1.9.pptx
Navsoft: AI-Powered Business Solutions & Custom Software Development

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