SlideShare uma empresa Scribd logo
1 de 13
Presentation on string.h
String.h- This header file defines several  functions to manipulate C strings and arrays. Functions declared in string.h are extremely popular since as a part of the C standard library, they are  guaranteed to work on any platform  which supports C Some of its functions are defined below .
Memcpy:-  Use Copy block of memory   SYNOPSIS #include <string.h> void *memcpy(void *s1, const void *s2, size_tn);   DESCRIPTION The memcpy() function copies n bytes from the object pointed to by s2 into the object pointed to by s1. If copying takes place between objects that overlap, the behaviour is undefined.   RETURN VALUE The memcpy() function returns s1; no return value is reserved to indicate an error.
Example /* memcpy example */ #include <stdio.h> #include <string.h>  int main () {   char str1[]="Sample string";  char str2[40];  char str3[40]; memcpy (str2,str1,strlen(str1)+1); memcpy (str3,"copy successful",16); printf ("str1: %sstr2: %sstr3: %s",str1,str2,str3);   return 0; } Output str1: Sample string str2: Sample string str3: copy successful
memmove memmove Memmove:- Use Move block of memory SYNOPSIS #include <string.h> void *memmove(void *s1, const void *s2, size_tn);   DESCRIPTION The memmove() function copies n bytes from the object pointed to by s2 into the object pointed  to by s1. Copying takes place as if the n bytes from the object pointed to by s2 are first copied  into a temporary array of n bytes that does not overlap the objects pointed to by s1 and s2,  and then the n bytes from the temporary array are copied into the object pointed to by s1.   RETURN VALUE The memmove() function returns s1; no return value is reserved to indicate an error.
Example /* memmove example */  #include <stdio.h>  #include <string.h> int main ()  {     char str[] = "memmove can be veryuseful......"; memmove (str+20,str+15,11);     puts (str);     return 0; }} } Output memmove can be very very useful.
Memcmp :- Use Compare two blocks of memory SYNOPSIS #include <string.h> intmemcmp(const void *s1, const void *s2, size_tn);   DESCRIPTION The memcmp() function compares the first n bytes of the object pointed to by s1 to the first  nbytes of the object pointed to by s2. The sign of a non-zero return value is determined by the sign of the difference between the values of the first pair of bytes that differ in the objects  being compared.    RETURN VALUE The memcmp() function returns an integer greater than, equal to or less than 0, if the object  pointed to by s1 is greater than, equal to or less than the object pointed to by s2 respectively.
Example /* memcmp example */ #include <stdio.h> #include <string.h>   int main () {   char str1[256];   char str2[256]; int n; size_t len1, len2; printf ("Enter a sentence: "); gets(str1); printf ("Enter another sentence: "); gets(str2);   len1=strlen(str1);   len2=strlen(str2);   n=memcmp ( str1, str2, len1>len2?len1:len2 );   if (n>0) printf ("'%s' is greater than '%s'.",str1,str2);   else if (n<0) printf ("'%s' is less than '%s'.",str1,str2);   else printf ("'%s' is the same as '%s'.",str1,str2);   return 0; } Output Enter a sentence: building Enter another sentence: book 'building' is greater than 'book'
Memset:- Use Fill block of memory SYNOPSIS #include <string.h> void *memset(void *s, intc, size_tn);   DESCRIPTION The memset() function copies c (converted to an unsigned char) into each of the first n bytes  of the object pointed to by s.   RETURN VALUE The memset() function returns s; no return value is reserved to indicate an error.
Example /* memset example */ #include <stdio.h> #include <string.h>   int main () {   char str[] = "almost every programmer should know memset!"; memset (str,'-',6);   puts (str);   return 0; } Output ------ every programmer should know memset!
Memchr Use Locate character in block of memory  SYNOPSIS #include <string.h> void *memchr(const void *s, intc, size_tn);  DESCRIPTION The memchr() function locates the first occurrence of c (converted to an unsigned char) in the  initial n bytes (each interpreted as unsigned char) of the object pointed to by s.   RETURN VALUE The memchr() function returns a pointer to the located byte, or a null pointer if the byte does  not occur in the object.
Example /* memchr example */ #include <stdio.h> #include <string.h>   int main () {   char * pch;   char str[] = "Example string"; pch = (char*) memchr (str, 'p', strlen(str));   if (pch!=NULL) printf ("'p' found at position %d.", pch-str+1);   else printf ("'p' not found.");   return 0; } Output 'p' found at position 5.
Thanks  for watching  .Hope u like it….. By :- NISHANK

Mais conteúdo relacionado

Mais procurados

String Handling in c++
String Handling in c++String Handling in c++
String Handling in c++
Fahim Adil
 
C++11: Feel the New Language
C++11: Feel the New LanguageC++11: Feel the New Language
C++11: Feel the New Language
mspline
 
Dd3.15 thru-3.21-advanced-functions
Dd3.15 thru-3.21-advanced-functionsDd3.15 thru-3.21-advanced-functions
Dd3.15 thru-3.21-advanced-functions
temkin abdlkader
 

Mais procurados (20)

Functions and pointers_unit_4
Functions and pointers_unit_4Functions and pointers_unit_4
Functions and pointers_unit_4
 
C++ 11 Features
C++ 11 FeaturesC++ 11 Features
C++ 11 Features
 
C programming(Part 1)
C programming(Part 1)C programming(Part 1)
C programming(Part 1)
 
Strings
StringsStrings
Strings
 
C++11 & C++14
C++11 & C++14C++11 & C++14
C++11 & C++14
 
String Handling in c++
String Handling in c++String Handling in c++
String Handling in c++
 
Maintainable go
Maintainable goMaintainable go
Maintainable go
 
Modern C++
Modern C++Modern C++
Modern C++
 
14 strings
14 strings14 strings
14 strings
 
7 functions
7  functions7  functions
7 functions
 
4 Type conversion functions
4 Type conversion functions4 Type conversion functions
4 Type conversion functions
 
Headerfiles
HeaderfilesHeaderfiles
Headerfiles
 
C++11: Feel the New Language
C++11: Feel the New LanguageC++11: Feel the New Language
C++11: Feel the New Language
 
4 operators, expressions &amp; statements
4  operators, expressions &amp; statements4  operators, expressions &amp; statements
4 operators, expressions &amp; statements
 
8 arrays and pointers
8  arrays and pointers8  arrays and pointers
8 arrays and pointers
 
1 introducing c language
1  introducing c language1  introducing c language
1 introducing c language
 
array, function, pointer, pattern matching
array, function, pointer, pattern matchingarray, function, pointer, pattern matching
array, function, pointer, pattern matching
 
Permute
PermutePermute
Permute
 
Pointers in C/C++ Programming
Pointers in C/C++ ProgrammingPointers in C/C++ Programming
Pointers in C/C++ Programming
 
Dd3.15 thru-3.21-advanced-functions
Dd3.15 thru-3.21-advanced-functionsDd3.15 thru-3.21-advanced-functions
Dd3.15 thru-3.21-advanced-functions
 

Semelhante a String .h

Lecture 15_Strings and Dynamic Memory Allocation.pptx
Lecture 15_Strings and  Dynamic Memory Allocation.pptxLecture 15_Strings and  Dynamic Memory Allocation.pptx
Lecture 15_Strings and Dynamic Memory Allocation.pptx
JawadTanvir
 
C aptitude questions
C aptitude questionsC aptitude questions
C aptitude questions
Srikanth
 
C - aptitude3
C - aptitude3C - aptitude3
C - aptitude3
Srikanth
 
booksoncprogramminglanguage-anintroductiontobeginnersbyarunumrao4-21101016591...
booksoncprogramminglanguage-anintroductiontobeginnersbyarunumrao4-21101016591...booksoncprogramminglanguage-anintroductiontobeginnersbyarunumrao4-21101016591...
booksoncprogramminglanguage-anintroductiontobeginnersbyarunumrao4-21101016591...
GkhanGirgin3
 
06 -working_with_strings
06  -working_with_strings06  -working_with_strings
06 -working_with_strings
Hector Garzo
 

Semelhante a String .h (20)

Lecture 15_Strings and Dynamic Memory Allocation.pptx
Lecture 15_Strings and  Dynamic Memory Allocation.pptxLecture 15_Strings and  Dynamic Memory Allocation.pptx
Lecture 15_Strings and Dynamic Memory Allocation.pptx
 
C++ Programming Homework Help
C++ Programming Homework HelpC++ Programming Homework Help
C++ Programming Homework Help
 
Linked list
Linked listLinked list
Linked list
 
Savitch Ch 08
Savitch Ch 08Savitch Ch 08
Savitch Ch 08
 
C aptitude questions
C aptitude questionsC aptitude questions
C aptitude questions
 
C - aptitude3
C - aptitude3C - aptitude3
C - aptitude3
 
Unit 2
Unit 2Unit 2
Unit 2
 
Unitii string
Unitii stringUnitii string
Unitii string
 
booksoncprogramminglanguage-anintroductiontobeginnersbyarunumrao4-21101016591...
booksoncprogramminglanguage-anintroductiontobeginnersbyarunumrao4-21101016591...booksoncprogramminglanguage-anintroductiontobeginnersbyarunumrao4-21101016591...
booksoncprogramminglanguage-anintroductiontobeginnersbyarunumrao4-21101016591...
 
Notes for C Programming for MCA, BCA, B. Tech CSE, ECE and MSC (CS) 4 of 5 by...
Notes for C Programming for MCA, BCA, B. Tech CSE, ECE and MSC (CS) 4 of 5 by...Notes for C Programming for MCA, BCA, B. Tech CSE, ECE and MSC (CS) 4 of 5 by...
Notes for C Programming for MCA, BCA, B. Tech CSE, ECE and MSC (CS) 4 of 5 by...
 
Savitch ch 08
Savitch ch 08Savitch ch 08
Savitch ch 08
 
Bsc cs i pic u-4 function, storage class and array and strings
Bsc cs i pic u-4 function, storage class and array and stringsBsc cs i pic u-4 function, storage class and array and strings
Bsc cs i pic u-4 function, storage class and array and strings
 
Btech i pic u-4 function, storage class and array and strings
Btech i pic u-4 function, storage class and array and stringsBtech i pic u-4 function, storage class and array and strings
Btech i pic u-4 function, storage class and array and strings
 
Functions torage class and array and strings-
Functions torage class and array and strings-Functions torage class and array and strings-
Functions torage class and array and strings-
 
Imugi: Compiler made with Python
Imugi: Compiler made with PythonImugi: Compiler made with Python
Imugi: Compiler made with Python
 
CPP Homework Help
CPP Homework HelpCPP Homework Help
CPP Homework Help
 
Diploma ii cfpc u-4 function, storage class and array and strings
Diploma ii  cfpc u-4 function, storage class and array and stringsDiploma ii  cfpc u-4 function, storage class and array and strings
Diploma ii cfpc u-4 function, storage class and array and strings
 
06 -working_with_strings
06  -working_with_strings06  -working_with_strings
06 -working_with_strings
 
Mcai pic u 4 function, storage class and array and strings
Mcai pic u 4 function, storage class and array and stringsMcai pic u 4 function, storage class and array and strings
Mcai pic u 4 function, storage class and array and strings
 
function, storage class and array and strings
 function, storage class and array and strings function, storage class and array and strings
function, storage class and array and strings
 

Último

Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
panagenda
 

Último (20)

Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024
 
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
 
A Beginners Guide to Building a RAG App Using Open Source Milvus
A Beginners Guide to Building a RAG App Using Open Source MilvusA Beginners Guide to Building a RAG App Using Open Source Milvus
A Beginners Guide to Building a RAG App Using Open Source Milvus
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
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
 
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
 
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
 
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptx
 
MS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsMS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectors
 
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
 
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)
 
Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot ModelNavi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot Model
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024
 
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
 
Apidays Singapore 2024 - Modernizing Securities Finance by Madhu Subbu
Apidays Singapore 2024 - Modernizing Securities Finance by Madhu SubbuApidays Singapore 2024 - Modernizing Securities Finance by Madhu Subbu
Apidays Singapore 2024 - Modernizing Securities Finance by Madhu Subbu
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 
ICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesICT role in 21st century education and its challenges
ICT role in 21st century education and its challenges
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 

String .h

  • 2. String.h- This header file defines several functions to manipulate C strings and arrays. Functions declared in string.h are extremely popular since as a part of the C standard library, they are guaranteed to work on any platform which supports C Some of its functions are defined below .
  • 3. Memcpy:- Use Copy block of memory   SYNOPSIS #include <string.h> void *memcpy(void *s1, const void *s2, size_tn);   DESCRIPTION The memcpy() function copies n bytes from the object pointed to by s2 into the object pointed to by s1. If copying takes place between objects that overlap, the behaviour is undefined.   RETURN VALUE The memcpy() function returns s1; no return value is reserved to indicate an error.
  • 4. Example /* memcpy example */ #include <stdio.h> #include <string.h>  int main () { char str1[]="Sample string"; char str2[40]; char str3[40]; memcpy (str2,str1,strlen(str1)+1); memcpy (str3,"copy successful",16); printf ("str1: %sstr2: %sstr3: %s",str1,str2,str3); return 0; } Output str1: Sample string str2: Sample string str3: copy successful
  • 5. memmove memmove Memmove:- Use Move block of memory SYNOPSIS #include <string.h> void *memmove(void *s1, const void *s2, size_tn);   DESCRIPTION The memmove() function copies n bytes from the object pointed to by s2 into the object pointed to by s1. Copying takes place as if the n bytes from the object pointed to by s2 are first copied into a temporary array of n bytes that does not overlap the objects pointed to by s1 and s2, and then the n bytes from the temporary array are copied into the object pointed to by s1.  RETURN VALUE The memmove() function returns s1; no return value is reserved to indicate an error.
  • 6. Example /* memmove example */ #include <stdio.h> #include <string.h> int main () { char str[] = "memmove can be veryuseful......"; memmove (str+20,str+15,11); puts (str); return 0; }} } Output memmove can be very very useful.
  • 7. Memcmp :- Use Compare two blocks of memory SYNOPSIS #include <string.h> intmemcmp(const void *s1, const void *s2, size_tn);   DESCRIPTION The memcmp() function compares the first n bytes of the object pointed to by s1 to the first nbytes of the object pointed to by s2. The sign of a non-zero return value is determined by the sign of the difference between the values of the first pair of bytes that differ in the objects being compared.   RETURN VALUE The memcmp() function returns an integer greater than, equal to or less than 0, if the object pointed to by s1 is greater than, equal to or less than the object pointed to by s2 respectively.
  • 8. Example /* memcmp example */ #include <stdio.h> #include <string.h>   int main () { char str1[256]; char str2[256]; int n; size_t len1, len2; printf ("Enter a sentence: "); gets(str1); printf ("Enter another sentence: "); gets(str2); len1=strlen(str1); len2=strlen(str2); n=memcmp ( str1, str2, len1>len2?len1:len2 ); if (n>0) printf ("'%s' is greater than '%s'.",str1,str2); else if (n<0) printf ("'%s' is less than '%s'.",str1,str2); else printf ("'%s' is the same as '%s'.",str1,str2); return 0; } Output Enter a sentence: building Enter another sentence: book 'building' is greater than 'book'
  • 9. Memset:- Use Fill block of memory SYNOPSIS #include <string.h> void *memset(void *s, intc, size_tn);  DESCRIPTION The memset() function copies c (converted to an unsigned char) into each of the first n bytes of the object pointed to by s.   RETURN VALUE The memset() function returns s; no return value is reserved to indicate an error.
  • 10. Example /* memset example */ #include <stdio.h> #include <string.h>   int main () { char str[] = "almost every programmer should know memset!"; memset (str,'-',6); puts (str); return 0; } Output ------ every programmer should know memset!
  • 11. Memchr Use Locate character in block of memory  SYNOPSIS #include <string.h> void *memchr(const void *s, intc, size_tn);  DESCRIPTION The memchr() function locates the first occurrence of c (converted to an unsigned char) in the initial n bytes (each interpreted as unsigned char) of the object pointed to by s.   RETURN VALUE The memchr() function returns a pointer to the located byte, or a null pointer if the byte does not occur in the object.
  • 12. Example /* memchr example */ #include <stdio.h> #include <string.h>   int main () { char * pch; char str[] = "Example string"; pch = (char*) memchr (str, 'p', strlen(str)); if (pch!=NULL) printf ("'p' found at position %d.", pch-str+1); else printf ("'p' not found."); return 0; } Output 'p' found at position 5.
  • 13. Thanks for watching .Hope u like it….. By :- NISHANK