SlideShare a Scribd company logo
1 of 20
String Functions in C
StringFunction
Thestandard library for C string
functions isstring.h
StringFunctions
• strlen()
• strcat()
• strcpy()
• strcmp()
strlen()
The strlen() function is used to calculate the length of
the string.
It counts the total number of characters present in the
string which includes alphabets, numbers, and all
special characters including blankspaces.
Program
Example 1
#include <stdio.h>
#include <string.h>
int main()
{
char a[20]="Programs";
printf("Length of string a = %d",strlen(a));
printf("n");
}
Program
Example 2
#include <stdio.h>
#include <string.h>
int main()
{
char a[50];
printf("Enter a string: ");
scanf("%s", a);
printf("Length of your string is = %d",strlen(a));
printf("n");
}
QUIZ - 1
#include <stdio.h>
#include <string.h>
int main()
{
char a[20]="I love Python Programming";
printf("Length of string a = %d",strlen(a));
printf("n");
}
The strcat() function is used for string concatenation
in Cprogramming language. It means it joins the two
strings together
strcat()
Program
Example 3
#include<stdio.h>
#include<string.h>
int main()
{
char str1[30]="www.cprogramming";
char str2[15]="expert.com";
printf("String 1: %s", str1);
printf("n");
printf("String 2: %s", str2);
printf("nn");
printf("Concatenated String: %s", strcat(str1, str2));
}
Program
Example 4
#include<stdio.h>
#include<string.h>
int main()
{
char str1[30];
char str2[30];
printf("Enter String 1: ");
scanf(" %s", str1);
printf("Enter String 2: ");
scanf("%s", str2);
printf("n");
printf("Concatenated String is: %s", strcat(str1, str2));
}
QUIZ - 2
#include<stdio.h>
#include<string.h>
int main()
{
char str1[30]="www.google";
char str2[15]=".com";
printf("Concatenated String: %s", strcat(str1, str2));
}
strcpy()
strcpy() function copies a string from a source location
to a destination location and provides a null character
to terminate thestring.
Program
Example 5
#include <stdio.h>
#include <string.h>
int main() {
char str1[20] = "C programming";
char str2[20];
// copying str1 to str2
strcpy(str2, str1);
printf("%s",str2); // C programming
return 0;
}
Program
Example 6
#include <stdio.h>
#include <string.h>
int main() {
char str1[20];
char str2[20];
printf("Enter a string: ");
scanf("%s", str1);
// copying str1 to str2
strcpy(str2, str1);
printf("The output of str2 is: %s",str2);
return 0;
}
strcmp()
strcmp()in C programminglanguageisused to comparetwo strings.
This function return values that are as follows −
• if Return value < 0 then it indicates str1 is less than str2.
• if Return value > 0 then it indicates str2 is less than str1.
• if Return value = 0 then it indicates str1 is equal to str2.
AMERICAN
STANDARD CODE
FOR INFORMATION
INTERCHANGE
TEXT ASCII TEXT ASCII
A 65 a 97
B 66 b 98
C 67 c 99
D 68 d 100
E 69 e 101
F 70 f 102
G 71 g 103
H 72 h 104
I 73 i 105
J 74 j 106
K 75 k 107
L 76 l 108
Program
Example 7
#include<stdio.h>
#include<string.h>
int main()
{
int ret;
char str1[10] = "awinash";
char str2[10] = "awi";
ret = strcmp(str1, str2);
//str1 > str2 == +
//str1 < str2 == -
//str1 == str2 equal
if(ret > 0) {
printf("str1 is greater than str2");
} else if(ret < 0) {
printf("str1 is less than str2");
} else {
printf("str1 is equal to str2");
}
}
QUIZ - 3
#include<stdio.h>
#include<string.h>
int main()
{
int ret;
char str1[10] = "Awinash Goswami - Computer Science Graduate";
char str2[10] = "awi";
ret = strcmp(str1, str2);
//str1 > str2 == +
//str1 < str2 == -
//str1 == str2 equal
if(ret > 0) {
printf("str1 is greater than str2");
} else if(ret < 0) {
printf("str1 is less than str2");
} else {
printf("str1 is equal to str2");
}
}
Assignment
 Declare two variables of char data type of size 20, take input from
user for initializing the string and perform following functions.
 find the length of first string.
 Concatenate the two strings.
For help, view slide number 6 and 9.
THEEND

More Related Content

What's hot (20)

Array
ArrayArray
Array
 
SaraPIC
SaraPICSaraPIC
SaraPIC
 
Let us C (by yashvant Kanetkar) chapter 3 Solution
Let us C   (by yashvant Kanetkar) chapter 3 SolutionLet us C   (by yashvant Kanetkar) chapter 3 Solution
Let us C (by yashvant Kanetkar) chapter 3 Solution
 
All important c programby makhan kumbhkar
All important c programby makhan kumbhkarAll important c programby makhan kumbhkar
All important c programby makhan kumbhkar
 
C Programming Exam problems & Solution by sazzad hossain
C Programming Exam problems & Solution by sazzad hossainC Programming Exam problems & Solution by sazzad hossain
C Programming Exam problems & Solution by sazzad hossain
 
C lab manaual
C lab manaualC lab manaual
C lab manaual
 
C programming
C programmingC programming
C programming
 
C faq pdf
C faq pdfC faq pdf
C faq pdf
 
C programms
C programmsC programms
C programms
 
C PROGRAMS
C PROGRAMSC PROGRAMS
C PROGRAMS
 
Basic c programs updated on 31.8.2020
Basic c programs updated on 31.8.2020Basic c programs updated on 31.8.2020
Basic c programs updated on 31.8.2020
 
String
StringString
String
 
C file
C fileC file
C file
 
Chapter 8 c solution
Chapter 8 c solutionChapter 8 c solution
Chapter 8 c solution
 
Cpds lab
Cpds labCpds lab
Cpds lab
 
DAA Lab File C Programs
DAA Lab File C ProgramsDAA Lab File C Programs
DAA Lab File C Programs
 
C Programming Example
C Programming ExampleC Programming Example
C Programming Example
 
Practical File of C Language
Practical File of C LanguagePractical File of C Language
Practical File of C Language
 
Solutionsfor co2 C Programs for data structures
Solutionsfor co2 C Programs for data structuresSolutionsfor co2 C Programs for data structures
Solutionsfor co2 C Programs for data structures
 
201801 CSE240 Lecture 08
201801 CSE240 Lecture 08201801 CSE240 Lecture 08
201801 CSE240 Lecture 08
 

Similar to Lecture 1 string functions

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 programmingCHAITRAB29
 
Library functions in c++
Library functions in c++Library functions in c++
Library functions in c++Neeru Mittal
 
Presentation more c_programmingcharacter_and_string_handling_
Presentation more c_programmingcharacter_and_string_handling_Presentation more c_programmingcharacter_and_string_handling_
Presentation more c_programmingcharacter_and_string_handling_KarthicaMarasamy
 
array, function, pointer, pattern matching
array, function, pointer, pattern matchingarray, function, pointer, pattern matching
array, function, pointer, pattern matchingShakila Mahjabin
 
Introduction to Basic C programming 02
Introduction to Basic C programming 02Introduction to Basic C programming 02
Introduction to Basic C programming 02Wingston
 
String predefined functions in C programming
String predefined functions in C  programmingString predefined functions in C  programming
String predefined functions in C programmingProfSonaliGholveDoif
 
ภาษาซี
ภาษาซีภาษาซี
ภาษาซีkramsri
 
Programming Fundamentals Arrays and Strings
Programming Fundamentals   Arrays and Strings Programming Fundamentals   Arrays and Strings
Programming Fundamentals Arrays and Strings imtiazalijoono
 
ภาษาซี
ภาษาซีภาษาซี
ภาษาซีkramsri
 
5 c control statements looping
5  c control statements looping5  c control statements looping
5 c control statements loopingMomenMostafa
 
C Programming Language Part 11
C Programming Language Part 11C Programming Language Part 11
C Programming Language Part 11Rumman Ansari
 
INDIAN INSTITUTE OF TECHNOLOGY KANPURESC 111M Lec13.pptx
INDIAN INSTITUTE OF TECHNOLOGY KANPURESC 111M Lec13.pptxINDIAN INSTITUTE OF TECHNOLOGY KANPURESC 111M Lec13.pptx
INDIAN INSTITUTE OF TECHNOLOGY KANPURESC 111M Lec13.pptxAbhimanyuChaure
 
manipulation of Strings+PPT.pptx
manipulation of Strings+PPT.pptxmanipulation of Strings+PPT.pptx
manipulation of Strings+PPT.pptxShowribabuKanta
 

Similar to Lecture 1 string functions (20)

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
 
Library functions in c++
Library functions in c++Library functions in c++
Library functions in c++
 
Unitii string
Unitii stringUnitii string
Unitii string
 
Lecture 2. mte 407
Lecture 2. mte 407Lecture 2. mte 407
Lecture 2. mte 407
 
Presentation more c_programmingcharacter_and_string_handling_
Presentation more c_programmingcharacter_and_string_handling_Presentation more c_programmingcharacter_and_string_handling_
Presentation more c_programmingcharacter_and_string_handling_
 
array, function, pointer, pattern matching
array, function, pointer, pattern matchingarray, function, pointer, pattern matching
array, function, pointer, pattern matching
 
String_C.pptx
String_C.pptxString_C.pptx
String_C.pptx
 
Introduction to Basic C programming 02
Introduction to Basic C programming 02Introduction to Basic C programming 02
Introduction to Basic C programming 02
 
String predefined functions in C programming
String predefined functions in C  programmingString predefined functions in C  programming
String predefined functions in C programming
 
ภาษาซี
ภาษาซีภาษาซี
ภาษาซี
 
String Manipulation Function and Header File Functions
String Manipulation Function and Header File FunctionsString Manipulation Function and Header File Functions
String Manipulation Function and Header File Functions
 
Programming Fundamentals Arrays and Strings
Programming Fundamentals   Arrays and Strings Programming Fundamentals   Arrays and Strings
Programming Fundamentals Arrays and Strings
 
ภาษาซี
ภาษาซีภาษาซี
ภาษาซี
 
Strings
StringsStrings
Strings
 
5 c control statements looping
5  c control statements looping5  c control statements looping
5 c control statements looping
 
Strings part2
Strings part2Strings part2
Strings part2
 
Tharun prakash.pptx
Tharun prakash.pptxTharun prakash.pptx
Tharun prakash.pptx
 
C Programming Language Part 11
C Programming Language Part 11C Programming Language Part 11
C Programming Language Part 11
 
INDIAN INSTITUTE OF TECHNOLOGY KANPURESC 111M Lec13.pptx
INDIAN INSTITUTE OF TECHNOLOGY KANPURESC 111M Lec13.pptxINDIAN INSTITUTE OF TECHNOLOGY KANPURESC 111M Lec13.pptx
INDIAN INSTITUTE OF TECHNOLOGY KANPURESC 111M Lec13.pptx
 
manipulation of Strings+PPT.pptx
manipulation of Strings+PPT.pptxmanipulation of Strings+PPT.pptx
manipulation of Strings+PPT.pptx
 

More from Awinash Goswami (19)

Database lecture 1
Database   lecture 1Database   lecture 1
Database lecture 1
 
Core Hardware: Lecture 8
Core Hardware: Lecture 8Core Hardware: Lecture 8
Core Hardware: Lecture 8
 
Core Hardware: Lecture 7
Core Hardware: Lecture 7Core Hardware: Lecture 7
Core Hardware: Lecture 7
 
Core Hardware: Lecture 6
Core Hardware: Lecture 6Core Hardware: Lecture 6
Core Hardware: Lecture 6
 
Software
SoftwareSoftware
Software
 
Core Hardware: Lecture 1
Core Hardware: Lecture 1Core Hardware: Lecture 1
Core Hardware: Lecture 1
 
Core Hardware: Lecture 4
Core Hardware: Lecture 4Core Hardware: Lecture 4
Core Hardware: Lecture 4
 
Core Hardware: Lecture 3
Core Hardware: Lecture 3Core Hardware: Lecture 3
Core Hardware: Lecture 3
 
Core Hardware: Lecture 2
Core Hardware: Lecture 2Core Hardware: Lecture 2
Core Hardware: Lecture 2
 
Class 5
Class 5Class 5
Class 5
 
Class 4
Class 4Class 4
Class 4
 
Class 3
Class 3Class 3
Class 3
 
Class 2
Class 2Class 2
Class 2
 
Class 1
Class 1Class 1
Class 1
 
Utility program
Utility programUtility program
Utility program
 
Microsoft windows
Microsoft windowsMicrosoft windows
Microsoft windows
 
Sufism
SufismSufism
Sufism
 
Industrial development in pakistan
Industrial development in pakistanIndustrial development in pakistan
Industrial development in pakistan
 
Resources of Pakistan
Resources of PakistanResources of Pakistan
Resources of Pakistan
 

Recently uploaded

What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?Antenna Manufacturer Coco
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024The Digital Insurer
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...Martijn de Jong
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsEnterprise Knowledge
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)Gabriella Davis
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Servicegiselly40
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityPrincipled Technologies
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking MenDelhi Call girls
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processorsdebabhi2
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...Neo4j
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc
 
Tech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdfTech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdfhans926745
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationSafe Software
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherRemote DBA Services
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)wesley chun
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationRadu Cotescu
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slidevu2urc
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonetsnaman860154
 

Recently uploaded (20)

What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
Tech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdfTech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdf
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 

Lecture 1 string functions