SlideShare a Scribd company logo
Presented By : Manas Chandra Sharma
A comprehensive overview of strings and their
implementation
Introduction to Strings in C
Strings are sequences of characters.
In C, strings are represented as arrays of characters, with a null
terminator '0' marking the end of the string.
String Representation in C
A string in C is an array of characters: char str[] = “Hello";
Strings are stored in contiguous memory locations.
Example: char str[] = {'H', 'e', 'l', 'l', 'o', ‘0'};
Declaring Strings in C
Strings can be declared in two ways:
1. Array of characters: char str[20];
2.String literal: char str[] = “Hello";
Basic String Operations
String operations include:
•Length of a string
•Concatenation
•Comparison
•Copying
•Searching
Null Terminator (0)
The null character '0' is used to mark the end of a string.
Essential to ensure that functions working with strings know where the
string ends.
String Length Function
The strlen() function is used to find the length of a string.
Syntax: size_t strlen(const char *str);
Caption
String Copy Function
The strcpy() function copies one string into another.
Syntax: char *strcpy(char *dest, const char *src);
String Concatenation
The strcat() function is used to concatenate two strings.
Syntax: char *strcat(char *dest, const char *src);
Caption
String Comparison
The strcmp() function compares two strings.
Syntax: int strcmp(const char *str1, const char *str2);
Returns 0 if strings are equal, a negative value if the first string is less,
and a positive value if the first string is greater.
String Search
The strchr() function searches for a character in a string.
Syntax: char *strchr(const char *str, int ch);
String Substring Search
The strstr() function finds the first occurrence of a substring.
Syntax : char *strstr(const char *haystack, const char *needle);
Caption
String to Integer Conversion
The atoi() function converts a string to an integer.
Syntax: int atoi(const char *str);
Caption
Integer to String Conversion
The sprintf() function converts an integer to a string.
Syntax: int sprintf(char *str, const char *format, …);
Caption
String Manipulation Functions Overview
Functions covered:
strlen(): Length of string
strcpy(): Copy string
strcat(): Concatenate strings
strcmp(): Compare strings
strchr(): Search for a character
strstr(): Find substring
atoi(): Convert string to integer
sprintf(): Convert integer to string
Common Pitfalls in String Handling
Not properly using the null terminator.
Buffer overflows from insufficient space in destination strings.
Forgetting to allocate enough space for strings during operations.
Dynamic Memory Allocation for Strings
Strings in C can also be dynamically allocated using malloc() or
calloc()
Example:
Caption
Best Practices for Handling Strings in C
Always ensure strings are null-terminated.
Avoid buffer overflows by allocating adequate memory.
Use safer alternatives like strncpy() and strncat() when possible.
Conclusion
Strings are fundamental in C programming, and understanding string
functions is key to efficient programming.
Always handle strings carefully to avoid common pitfalls like buffer
overflows and improper null-termination.
Thank You
Ad

More Related Content

Similar to Strings In C and its syntax and uses .ppt (20)

C string
C stringC string
C string
University of Potsdam
 
All_About_Strings_in_C_Programming.pptxn
All_About_Strings_in_C_Programming.pptxnAll_About_Strings_in_C_Programming.pptxn
All_About_Strings_in_C_Programming.pptxn
kumarsahil80682
 
0-Slot21-22-Strings.pdf
0-Slot21-22-Strings.pdf0-Slot21-22-Strings.pdf
0-Slot21-22-Strings.pdf
ssusere19c741
 
string in C
string in Cstring in C
string in C
CGC Technical campus,Mohali
 
Strings in c
Strings in cStrings in c
Strings in c
vampugani
 
Basic Algorithms and Array along with Structure.pptx
Basic Algorithms and Array along with Structure.pptxBasic Algorithms and Array along with Structure.pptx
Basic Algorithms and Array along with Structure.pptx
MrNikhilMohanShinde
 
Strings
StringsStrings
Strings
Mitali Chugh
 
fundamentals of c programming_String.pptx
fundamentals of c programming_String.pptxfundamentals of c programming_String.pptx
fundamentals of c programming_String.pptx
JStalinAsstProfessor
 
ARRAY's in C Programming Language PPTX.
ARRAY's in C  Programming Language PPTX.ARRAY's in C  Programming Language PPTX.
ARRAY's in C Programming Language PPTX.
MSridhar18
 
Operation on string presentation
Operation on string presentationOperation on string presentation
Operation on string presentation
Aliul Kadir Akib
 
String notes
String notesString notes
String notes
Prasadu Peddi
 
Principals of Programming in CModule -5.pdfModule-4.pdf
Principals of Programming in CModule -5.pdfModule-4.pdfPrincipals of Programming in CModule -5.pdfModule-4.pdf
Principals of Programming in CModule -5.pdfModule-4.pdf
anilcsbs
 
Unitii string
Unitii stringUnitii string
Unitii string
Sowri Rajan
 
Team 1
Team 1Team 1
Team 1
Sathasivam Rangasamy
 
Lecture 2. mte 407
Lecture 2. mte 407Lecture 2. mte 407
Lecture 2. mte 407
rumanatasnim415
 
UNIT 4C-Strings.pptx for c language and basic knowledge
UNIT 4C-Strings.pptx for c language and basic knowledgeUNIT 4C-Strings.pptx for c language and basic knowledge
UNIT 4C-Strings.pptx for c language and basic knowledge
2024163103shubham
 
Character Array and String
Character Array and StringCharacter Array and String
Character Array and String
Tasnima Hamid
 
CP-STRING (1).ppt
CP-STRING (1).pptCP-STRING (1).ppt
CP-STRING (1).ppt
mounikanarra3
 
CP-STRING.ppt
CP-STRING.pptCP-STRING.ppt
CP-STRING.ppt
TAPANDDRAW
 
CP-STRING.ppt
CP-STRING.pptCP-STRING.ppt
CP-STRING.ppt
arunatluri
 
All_About_Strings_in_C_Programming.pptxn
All_About_Strings_in_C_Programming.pptxnAll_About_Strings_in_C_Programming.pptxn
All_About_Strings_in_C_Programming.pptxn
kumarsahil80682
 
0-Slot21-22-Strings.pdf
0-Slot21-22-Strings.pdf0-Slot21-22-Strings.pdf
0-Slot21-22-Strings.pdf
ssusere19c741
 
Strings in c
Strings in cStrings in c
Strings in c
vampugani
 
Basic Algorithms and Array along with Structure.pptx
Basic Algorithms and Array along with Structure.pptxBasic Algorithms and Array along with Structure.pptx
Basic Algorithms and Array along with Structure.pptx
MrNikhilMohanShinde
 
fundamentals of c programming_String.pptx
fundamentals of c programming_String.pptxfundamentals of c programming_String.pptx
fundamentals of c programming_String.pptx
JStalinAsstProfessor
 
ARRAY's in C Programming Language PPTX.
ARRAY's in C  Programming Language PPTX.ARRAY's in C  Programming Language PPTX.
ARRAY's in C Programming Language PPTX.
MSridhar18
 
Operation on string presentation
Operation on string presentationOperation on string presentation
Operation on string presentation
Aliul Kadir Akib
 
Principals of Programming in CModule -5.pdfModule-4.pdf
Principals of Programming in CModule -5.pdfModule-4.pdfPrincipals of Programming in CModule -5.pdfModule-4.pdf
Principals of Programming in CModule -5.pdfModule-4.pdf
anilcsbs
 
UNIT 4C-Strings.pptx for c language and basic knowledge
UNIT 4C-Strings.pptx for c language and basic knowledgeUNIT 4C-Strings.pptx for c language and basic knowledge
UNIT 4C-Strings.pptx for c language and basic knowledge
2024163103shubham
 
Character Array and String
Character Array and StringCharacter Array and String
Character Array and String
Tasnima Hamid
 

Recently uploaded (20)

TERMINOLOGIES,GRIEF PROCESS AND LOSS AMD ITS TYPES .pptx
TERMINOLOGIES,GRIEF PROCESS AND LOSS AMD ITS TYPES .pptxTERMINOLOGIES,GRIEF PROCESS AND LOSS AMD ITS TYPES .pptx
TERMINOLOGIES,GRIEF PROCESS AND LOSS AMD ITS TYPES .pptx
PoojaSen20
 
What is the Philosophy of Statistics? (and how I was drawn to it)
What is the Philosophy of Statistics? (and how I was drawn to it)What is the Philosophy of Statistics? (and how I was drawn to it)
What is the Philosophy of Statistics? (and how I was drawn to it)
jemille6
 
ANTI-VIRAL DRUGS unit 3 Pharmacology 3.pptx
ANTI-VIRAL DRUGS unit 3 Pharmacology 3.pptxANTI-VIRAL DRUGS unit 3 Pharmacology 3.pptx
ANTI-VIRAL DRUGS unit 3 Pharmacology 3.pptx
Mayuri Chavan
 
History Of The Monastery Of Mor Gabriel Philoxenos Yuhanon Dolabani
History Of The Monastery Of Mor Gabriel Philoxenos Yuhanon DolabaniHistory Of The Monastery Of Mor Gabriel Philoxenos Yuhanon Dolabani
History Of The Monastery Of Mor Gabriel Philoxenos Yuhanon Dolabani
fruinkamel7m
 
puzzle Irregular Verbs- Simple Past Tense
puzzle Irregular Verbs- Simple Past Tensepuzzle Irregular Verbs- Simple Past Tense
puzzle Irregular Verbs- Simple Past Tense
OlgaLeonorTorresSnch
 
U3 ANTITUBERCULAR DRUGS Pharmacology 3.pptx
U3 ANTITUBERCULAR DRUGS Pharmacology 3.pptxU3 ANTITUBERCULAR DRUGS Pharmacology 3.pptx
U3 ANTITUBERCULAR DRUGS Pharmacology 3.pptx
Mayuri Chavan
 
How to Manage Amounts in Local Currency in Odoo 18 Purchase
How to Manage Amounts in Local Currency in Odoo 18 PurchaseHow to Manage Amounts in Local Currency in Odoo 18 Purchase
How to Manage Amounts in Local Currency in Odoo 18 Purchase
Celine George
 
Ajanta Paintings: Study as a Source of History
Ajanta Paintings: Study as a Source of HistoryAjanta Paintings: Study as a Source of History
Ajanta Paintings: Study as a Source of History
Virag Sontakke
 
Cultivation Practice of Garlic in Nepal.pptx
Cultivation Practice of Garlic in Nepal.pptxCultivation Practice of Garlic in Nepal.pptx
Cultivation Practice of Garlic in Nepal.pptx
UmeshTimilsina1
 
Final Evaluation.docx...........................
Final Evaluation.docx...........................Final Evaluation.docx...........................
Final Evaluation.docx...........................
l1bbyburrell
 
The History of Kashmir Karkota Dynasty NEP.pptx
The History of Kashmir Karkota Dynasty NEP.pptxThe History of Kashmir Karkota Dynasty NEP.pptx
The History of Kashmir Karkota Dynasty NEP.pptx
Arya Mahila P. G. College, Banaras Hindu University, Varanasi, India.
 
How to Clean Your Contacts Using the Deduplication Menu in Odoo 18
How to Clean Your Contacts Using the Deduplication Menu in Odoo 18How to Clean Your Contacts Using the Deduplication Menu in Odoo 18
How to Clean Your Contacts Using the Deduplication Menu in Odoo 18
Celine George
 
Transform tomorrow: Master benefits analysis with Gen AI today webinar, 30 A...
Transform tomorrow: Master benefits analysis with Gen AI today webinar,  30 A...Transform tomorrow: Master benefits analysis with Gen AI today webinar,  30 A...
Transform tomorrow: Master benefits analysis with Gen AI today webinar, 30 A...
Association for Project Management
 
Cultivation Practice of Onion in Nepal.pptx
Cultivation Practice of Onion in Nepal.pptxCultivation Practice of Onion in Nepal.pptx
Cultivation Practice of Onion in Nepal.pptx
UmeshTimilsina1
 
How to Manage Upselling in Odoo 18 Sales
How to Manage Upselling in Odoo 18 SalesHow to Manage Upselling in Odoo 18 Sales
How to Manage Upselling in Odoo 18 Sales
Celine George
 
How to Configure Scheduled Actions in odoo 18
How to Configure Scheduled Actions in odoo 18How to Configure Scheduled Actions in odoo 18
How to Configure Scheduled Actions in odoo 18
Celine George
 
Overview Well-Being and Creative Careers
Overview Well-Being and Creative CareersOverview Well-Being and Creative Careers
Overview Well-Being and Creative Careers
University of Amsterdam
 
UPMVLE migration to ARAL. A step- by- step guide
UPMVLE migration to ARAL. A step- by- step guideUPMVLE migration to ARAL. A step- by- step guide
UPMVLE migration to ARAL. A step- by- step guide
abmerca
 
Chemotherapy of Malignancy -Anticancer.pptx
Chemotherapy of Malignancy -Anticancer.pptxChemotherapy of Malignancy -Anticancer.pptx
Chemotherapy of Malignancy -Anticancer.pptx
Mayuri Chavan
 
BÀI TẬP BỔ TRỢ TIẾNG ANH 9 THEO ĐƠN VỊ BÀI HỌC - GLOBAL SUCCESS - CẢ NĂM (TỪ...
BÀI TẬP BỔ TRỢ TIẾNG ANH 9 THEO ĐƠN VỊ BÀI HỌC - GLOBAL SUCCESS - CẢ NĂM (TỪ...BÀI TẬP BỔ TRỢ TIẾNG ANH 9 THEO ĐƠN VỊ BÀI HỌC - GLOBAL SUCCESS - CẢ NĂM (TỪ...
BÀI TẬP BỔ TRỢ TIẾNG ANH 9 THEO ĐƠN VỊ BÀI HỌC - GLOBAL SUCCESS - CẢ NĂM (TỪ...
Nguyen Thanh Tu Collection
 
TERMINOLOGIES,GRIEF PROCESS AND LOSS AMD ITS TYPES .pptx
TERMINOLOGIES,GRIEF PROCESS AND LOSS AMD ITS TYPES .pptxTERMINOLOGIES,GRIEF PROCESS AND LOSS AMD ITS TYPES .pptx
TERMINOLOGIES,GRIEF PROCESS AND LOSS AMD ITS TYPES .pptx
PoojaSen20
 
What is the Philosophy of Statistics? (and how I was drawn to it)
What is the Philosophy of Statistics? (and how I was drawn to it)What is the Philosophy of Statistics? (and how I was drawn to it)
What is the Philosophy of Statistics? (and how I was drawn to it)
jemille6
 
ANTI-VIRAL DRUGS unit 3 Pharmacology 3.pptx
ANTI-VIRAL DRUGS unit 3 Pharmacology 3.pptxANTI-VIRAL DRUGS unit 3 Pharmacology 3.pptx
ANTI-VIRAL DRUGS unit 3 Pharmacology 3.pptx
Mayuri Chavan
 
History Of The Monastery Of Mor Gabriel Philoxenos Yuhanon Dolabani
History Of The Monastery Of Mor Gabriel Philoxenos Yuhanon DolabaniHistory Of The Monastery Of Mor Gabriel Philoxenos Yuhanon Dolabani
History Of The Monastery Of Mor Gabriel Philoxenos Yuhanon Dolabani
fruinkamel7m
 
puzzle Irregular Verbs- Simple Past Tense
puzzle Irregular Verbs- Simple Past Tensepuzzle Irregular Verbs- Simple Past Tense
puzzle Irregular Verbs- Simple Past Tense
OlgaLeonorTorresSnch
 
U3 ANTITUBERCULAR DRUGS Pharmacology 3.pptx
U3 ANTITUBERCULAR DRUGS Pharmacology 3.pptxU3 ANTITUBERCULAR DRUGS Pharmacology 3.pptx
U3 ANTITUBERCULAR DRUGS Pharmacology 3.pptx
Mayuri Chavan
 
How to Manage Amounts in Local Currency in Odoo 18 Purchase
How to Manage Amounts in Local Currency in Odoo 18 PurchaseHow to Manage Amounts in Local Currency in Odoo 18 Purchase
How to Manage Amounts in Local Currency in Odoo 18 Purchase
Celine George
 
Ajanta Paintings: Study as a Source of History
Ajanta Paintings: Study as a Source of HistoryAjanta Paintings: Study as a Source of History
Ajanta Paintings: Study as a Source of History
Virag Sontakke
 
Cultivation Practice of Garlic in Nepal.pptx
Cultivation Practice of Garlic in Nepal.pptxCultivation Practice of Garlic in Nepal.pptx
Cultivation Practice of Garlic in Nepal.pptx
UmeshTimilsina1
 
Final Evaluation.docx...........................
Final Evaluation.docx...........................Final Evaluation.docx...........................
Final Evaluation.docx...........................
l1bbyburrell
 
How to Clean Your Contacts Using the Deduplication Menu in Odoo 18
How to Clean Your Contacts Using the Deduplication Menu in Odoo 18How to Clean Your Contacts Using the Deduplication Menu in Odoo 18
How to Clean Your Contacts Using the Deduplication Menu in Odoo 18
Celine George
 
Transform tomorrow: Master benefits analysis with Gen AI today webinar, 30 A...
Transform tomorrow: Master benefits analysis with Gen AI today webinar,  30 A...Transform tomorrow: Master benefits analysis with Gen AI today webinar,  30 A...
Transform tomorrow: Master benefits analysis with Gen AI today webinar, 30 A...
Association for Project Management
 
Cultivation Practice of Onion in Nepal.pptx
Cultivation Practice of Onion in Nepal.pptxCultivation Practice of Onion in Nepal.pptx
Cultivation Practice of Onion in Nepal.pptx
UmeshTimilsina1
 
How to Manage Upselling in Odoo 18 Sales
How to Manage Upselling in Odoo 18 SalesHow to Manage Upselling in Odoo 18 Sales
How to Manage Upselling in Odoo 18 Sales
Celine George
 
How to Configure Scheduled Actions in odoo 18
How to Configure Scheduled Actions in odoo 18How to Configure Scheduled Actions in odoo 18
How to Configure Scheduled Actions in odoo 18
Celine George
 
Overview Well-Being and Creative Careers
Overview Well-Being and Creative CareersOverview Well-Being and Creative Careers
Overview Well-Being and Creative Careers
University of Amsterdam
 
UPMVLE migration to ARAL. A step- by- step guide
UPMVLE migration to ARAL. A step- by- step guideUPMVLE migration to ARAL. A step- by- step guide
UPMVLE migration to ARAL. A step- by- step guide
abmerca
 
Chemotherapy of Malignancy -Anticancer.pptx
Chemotherapy of Malignancy -Anticancer.pptxChemotherapy of Malignancy -Anticancer.pptx
Chemotherapy of Malignancy -Anticancer.pptx
Mayuri Chavan
 
BÀI TẬP BỔ TRỢ TIẾNG ANH 9 THEO ĐƠN VỊ BÀI HỌC - GLOBAL SUCCESS - CẢ NĂM (TỪ...
BÀI TẬP BỔ TRỢ TIẾNG ANH 9 THEO ĐƠN VỊ BÀI HỌC - GLOBAL SUCCESS - CẢ NĂM (TỪ...BÀI TẬP BỔ TRỢ TIẾNG ANH 9 THEO ĐƠN VỊ BÀI HỌC - GLOBAL SUCCESS - CẢ NĂM (TỪ...
BÀI TẬP BỔ TRỢ TIẾNG ANH 9 THEO ĐƠN VỊ BÀI HỌC - GLOBAL SUCCESS - CẢ NĂM (TỪ...
Nguyen Thanh Tu Collection
 
Ad

Strings In C and its syntax and uses .ppt

  • 1. Presented By : Manas Chandra Sharma A comprehensive overview of strings and their implementation
  • 2. Introduction to Strings in C Strings are sequences of characters. In C, strings are represented as arrays of characters, with a null terminator '0' marking the end of the string.
  • 3. String Representation in C A string in C is an array of characters: char str[] = “Hello"; Strings are stored in contiguous memory locations. Example: char str[] = {'H', 'e', 'l', 'l', 'o', ‘0'};
  • 4. Declaring Strings in C Strings can be declared in two ways: 1. Array of characters: char str[20]; 2.String literal: char str[] = “Hello";
  • 5. Basic String Operations String operations include: •Length of a string •Concatenation •Comparison •Copying •Searching
  • 6. Null Terminator (0) The null character '0' is used to mark the end of a string. Essential to ensure that functions working with strings know where the string ends.
  • 7. String Length Function The strlen() function is used to find the length of a string. Syntax: size_t strlen(const char *str); Caption
  • 8. String Copy Function The strcpy() function copies one string into another. Syntax: char *strcpy(char *dest, const char *src);
  • 9. String Concatenation The strcat() function is used to concatenate two strings. Syntax: char *strcat(char *dest, const char *src); Caption
  • 10. String Comparison The strcmp() function compares two strings. Syntax: int strcmp(const char *str1, const char *str2); Returns 0 if strings are equal, a negative value if the first string is less, and a positive value if the first string is greater.
  • 11. String Search The strchr() function searches for a character in a string. Syntax: char *strchr(const char *str, int ch);
  • 12. String Substring Search The strstr() function finds the first occurrence of a substring. Syntax : char *strstr(const char *haystack, const char *needle); Caption
  • 13. String to Integer Conversion The atoi() function converts a string to an integer. Syntax: int atoi(const char *str); Caption
  • 14. Integer to String Conversion The sprintf() function converts an integer to a string. Syntax: int sprintf(char *str, const char *format, …); Caption
  • 15. String Manipulation Functions Overview Functions covered: strlen(): Length of string strcpy(): Copy string strcat(): Concatenate strings strcmp(): Compare strings strchr(): Search for a character strstr(): Find substring atoi(): Convert string to integer sprintf(): Convert integer to string
  • 16. Common Pitfalls in String Handling Not properly using the null terminator. Buffer overflows from insufficient space in destination strings. Forgetting to allocate enough space for strings during operations.
  • 17. Dynamic Memory Allocation for Strings Strings in C can also be dynamically allocated using malloc() or calloc() Example: Caption
  • 18. Best Practices for Handling Strings in C Always ensure strings are null-terminated. Avoid buffer overflows by allocating adequate memory. Use safer alternatives like strncpy() and strncat() when possible.
  • 19. Conclusion Strings are fundamental in C programming, and understanding string functions is key to efficient programming. Always handle strings carefully to avoid common pitfalls like buffer overflows and improper null-termination.
  翻译: