SlideShare a Scribd company logo
1 of 16
Lectures on Busy Bee Workshop 1
Busy Bee Workshop – Session VIBusy Bee Workshop – Session VI
This session Outline
String
String Manipulation Functions
String Programs
Lectures on Busy Bee Workshop 2
String in CString in C
Sequence of characters is called string.
In C, a string constant is a sequence of
characters enclosed in double quotes.
Examples:
“C Programming”
“SVN College”
“3/390 Nehru Street”
“45”
Lectures on Busy Bee Workshop 3
String in C - ImplementationString in C - Implementation
• C implements the stringstring data structure
using arrays of type char.
• We have already used the string
extensively.
– printf(“This program is terminated!n”);
– #define ERR_Message “Error!!”
• Since stringstring is an array, the declaration of
a string is the same as declaring a char
array.
– char string_var[30];
– char string_var[20] = “Initial value”;
Lectures on Busy Bee Workshop 4
String in C – Memory StorageString in C – Memory Storage
• The string is always ended with a nullnull
charactercharacter ‘0’‘0’.
• The characters after the null character are
ignored.
• e.g., char str[20] = “Initial value”;
n i t i a l v a l u e ? ? …I 00
[0] [13]
Lectures on Busy Bee Workshop 5
String in C – Arrays of StringsString in C – Arrays of Strings
• An array of strings is a two-dimensional
array of characters in which each row is one
string.
– char names[People][Length];
– char names[10][25];
– char month[5][10] = {“January”,
“February”, “March”, “April”, “May”};
Lectures on Busy Bee Workshop 6
String in C – Character vs. StringString in C – Character vs. String
Lectures on Busy Bee Workshop 7
String in C – Input/OutputString in C – Input/Output
• The placeholder %s%s is used to represent
string arguments in printf and scanf.
• Example:
char message1[12] = "Hello world";
printf(“%s”,message1);
message1:
char message2[12];
scanf(“%s”,message2); // type "Hello" as input
message2:
H e l l o w o r l d 0
H e l l o 0 ? ? ? ? ? ?
Lectures on Busy Bee Workshop 8
String in C – Right and Left Justification of StringsString in C – Right and Left Justification of Strings
• The string can be right-justified by placing a
positive number in the placeholder.
– printf(“%8s%8s”, str);
• The string can be left-justified by placing a
negative number in the placeholder.
– Printf(“%-8s%-8s”, str);
Lectures on Busy Bee Workshop 9
String in C – Example programString in C – Example program
Lectures on Busy Bee Workshop 10
String in C – Library FunctionsString in C – Library Functions
• The string can not be copied by the
assignment operator ‘=’.
– e..g, “str = “Test String”” is not valid.
• C provides string manipulating
functions in the “string.h” library.
– The list of these functions can be found in the next slide.
Lectures on Busy Bee Workshop 11
String in C – Library FunctionsString in C – Library Functions
Function Purpose Example
strcpy Makes a copy of a string strcpy(s1, “Hi”);
strcat Appends a string to the
end of another string
strcat(s1, “more”);
strcmp Compare two strings
alphabetically
strcmp(s1, “Hu”);
strlen Returns the number of
characters in a string
strlen(“Hi”) returns
2.
strtok Breaks a string into
tokens by delimiters.
strtok(“Hi, Chao”, “ ,”);
Lectures on Busy Bee Workshop 12
String in C – Library FunctionsString in C – Library Functions
Function Purpose Example
Strncpy Copy the specified
number of characters
strncpy(s1,
“SVN”,2);
Strncmp Compare two string upto
given n character
strncmp(“mo”,
“more”,2);
Stricmp Compare two strings
alphabetically without case
sensitivity.
stricmp(“hu”, “Hu”);
strlwr Converts string to all
lowercase
strlwr(“Hi”) returns
hi.
strupr Converts s to all
uppercase
strupr(“Hi”);
Lectures on Busy Bee Workshop 13
String in C – Library FunctionsString in C – Library Functions
Function Purpose Example
Strncat Appends a string to the
end of another string up
to n characters
strncat(s1,
“more”,2);
Strrev Reverses all characters
in s1 (except for the
terminating null)
strrev(s1, “more”);
Lectures on Busy Bee Workshop 14
String in C – Example program (Library Function)String in C – Example program (Library Function)
String c
String c

More Related Content

What's hot (20)

C Structures and Unions
C Structures and UnionsC Structures and Unions
C Structures and Unions
 
String In C Language
String In C Language String In C Language
String In C Language
 
String in c
String in cString in c
String in c
 
Implementation Of String Functions In C
Implementation Of String Functions In CImplementation Of String Functions In C
Implementation Of String Functions In C
 
Programming in c Arrays
Programming in c ArraysProgramming in c Arrays
Programming in c Arrays
 
Handling of character strings C programming
Handling of character strings C programmingHandling of character strings C programming
Handling of character strings C programming
 
Arrays in c
Arrays in cArrays in c
Arrays in c
 
Arrays and Strings
Arrays and Strings Arrays and Strings
Arrays and Strings
 
Call by value or call by reference in C++
Call by value or call by reference in C++Call by value or call by reference in C++
Call by value or call by reference in C++
 
Stack using Array
Stack using ArrayStack using Array
Stack using Array
 
String in c programming
String in c programmingString in c programming
String in c programming
 
C Programming: Control Structure
C Programming: Control StructureC Programming: Control Structure
C Programming: Control Structure
 
Unit 3. Input and Output
Unit 3. Input and OutputUnit 3. Input and Output
Unit 3. Input and Output
 
Strings in C language
Strings in C languageStrings in C language
Strings in C language
 
Strings Functions in C Programming
Strings Functions in C ProgrammingStrings Functions in C Programming
Strings Functions in C Programming
 
Strings in C
Strings in CStrings in C
Strings in C
 
C string
C stringC string
C string
 
File handling in c
File handling in cFile handling in c
File handling in c
 
Array and string
Array and stringArray and string
Array and string
 
Control structures in c
Control structures in cControl structures in c
Control structures in c
 

Viewers also liked (13)

Loops Basics
Loops BasicsLoops Basics
Loops Basics
 
Function in c
Function in cFunction in c
Function in c
 
Structure in C
Structure in CStructure in C
Structure in C
 
Arrays in C language
Arrays in C languageArrays in C language
Arrays in C language
 
Structure c
Structure cStructure c
Structure c
 
Structure of a C program
Structure of a C programStructure of a C program
Structure of a C program
 
String functions in C
String functions in CString functions in C
String functions in C
 
Structure in c
Structure in cStructure in c
Structure in c
 
Loops in C
Loops in CLoops in C
Loops in C
 
Loops in C Programming
Loops in C ProgrammingLoops in C Programming
Loops in C Programming
 
Array in c language
Array in c languageArray in c language
Array in c language
 
Functions in C
Functions in CFunctions in C
Functions in C
 
Function in C program
Function in C programFunction in C program
Function in C program
 

Similar to String c (20)

5 2. string processing
5 2. string processing5 2. string processing
5 2. string processing
 
24_2-String and String Library.pptx
24_2-String and String Library.pptx24_2-String and String Library.pptx
24_2-String and String Library.pptx
 
introduction to strings in c programming
introduction to strings in c programmingintroduction to strings in c programming
introduction to strings in c programming
 
fundamentals of c programming_String.pptx
fundamentals of c programming_String.pptxfundamentals of c programming_String.pptx
fundamentals of c programming_String.pptx
 
[ITP - Lecture 17] Strings in C/C++
[ITP - Lecture 17] Strings in C/C++[ITP - Lecture 17] Strings in C/C++
[ITP - Lecture 17] Strings in C/C++
 
Strings in c++
Strings in c++Strings in c++
Strings in c++
 
string in C
string in Cstring in C
string in C
 
Week6_P_String.pptx
Week6_P_String.pptxWeek6_P_String.pptx
Week6_P_String.pptx
 
Strings CPU GTU
Strings CPU GTUStrings CPU GTU
Strings CPU GTU
 
Strings
StringsStrings
Strings
 
COm1407: Character & Strings
COm1407: Character & StringsCOm1407: Character & Strings
COm1407: Character & Strings
 
U4.ppt
U4.pptU4.ppt
U4.ppt
 
lecture5.ppt
lecture5.pptlecture5.ppt
lecture5.ppt
 
Matlab strings
Matlab stringsMatlab strings
Matlab strings
 
0-Slot21-22-Strings.pdf
0-Slot21-22-Strings.pdf0-Slot21-22-Strings.pdf
0-Slot21-22-Strings.pdf
 
Strings in c mrs.sowmya jyothi
Strings in c mrs.sowmya jyothiStrings in c mrs.sowmya jyothi
Strings in c mrs.sowmya jyothi
 
CPSTRINGSARGAVISTRINGS.PPT
CPSTRINGSARGAVISTRINGS.PPTCPSTRINGSARGAVISTRINGS.PPT
CPSTRINGSARGAVISTRINGS.PPT
 
BHARGAVISTRINGS.PPT
BHARGAVISTRINGS.PPTBHARGAVISTRINGS.PPT
BHARGAVISTRINGS.PPT
 
String in programming language in c or c++
String in programming language in c or c++String in programming language in c or c++
String in programming language in c or c++
 
14 strings
14 strings14 strings
14 strings
 

More from thirumalaikumar3 (8)

Data type in c
Data type in cData type in c
Data type in c
 
Control flow in c
Control flow in cControl flow in c
Control flow in c
 
C function
C functionC function
C function
 
Coper in C
Coper in CCoper in C
Coper in C
 
C basics
C   basicsC   basics
C basics
 
File handling in c
File  handling in cFile  handling in c
File handling in c
 
File handling-c programming language
File handling-c programming languageFile handling-c programming language
File handling-c programming language
 
Data type2 c
Data type2 cData type2 c
Data type2 c
 

Recently uploaded

Reading and Writing Skills 11 quarter 4 melc 1
Reading and Writing Skills 11 quarter 4 melc 1Reading and Writing Skills 11 quarter 4 melc 1
Reading and Writing Skills 11 quarter 4 melc 1GloryAnnCastre1
 
CHEST Proprioceptive neuromuscular facilitation.pptx
CHEST Proprioceptive neuromuscular facilitation.pptxCHEST Proprioceptive neuromuscular facilitation.pptx
CHEST Proprioceptive neuromuscular facilitation.pptxAneriPatwari
 
CLASSIFICATION OF ANTI - CANCER DRUGS.pptx
CLASSIFICATION OF ANTI - CANCER DRUGS.pptxCLASSIFICATION OF ANTI - CANCER DRUGS.pptx
CLASSIFICATION OF ANTI - CANCER DRUGS.pptxAnupam32727
 
Oppenheimer Film Discussion for Philosophy and Film
Oppenheimer Film Discussion for Philosophy and FilmOppenheimer Film Discussion for Philosophy and Film
Oppenheimer Film Discussion for Philosophy and FilmStan Meyer
 
How to Fix XML SyntaxError in Odoo the 17
How to Fix XML SyntaxError in Odoo the 17How to Fix XML SyntaxError in Odoo the 17
How to Fix XML SyntaxError in Odoo the 17Celine George
 
Indexing Structures in Database Management system.pdf
Indexing Structures in Database Management system.pdfIndexing Structures in Database Management system.pdf
Indexing Structures in Database Management system.pdfChristalin Nelson
 
Sulphonamides, mechanisms and their uses
Sulphonamides, mechanisms and their usesSulphonamides, mechanisms and their uses
Sulphonamides, mechanisms and their usesVijayaLaxmi84
 
4.16.24 21st Century Movements for Black Lives.pptx
4.16.24 21st Century Movements for Black Lives.pptx4.16.24 21st Century Movements for Black Lives.pptx
4.16.24 21st Century Movements for Black Lives.pptxmary850239
 
Daily Lesson Plan in Mathematics Quarter 4
Daily Lesson Plan in Mathematics Quarter 4Daily Lesson Plan in Mathematics Quarter 4
Daily Lesson Plan in Mathematics Quarter 4JOYLYNSAMANIEGO
 
4.16.24 Poverty and Precarity--Desmond.pptx
4.16.24 Poverty and Precarity--Desmond.pptx4.16.24 Poverty and Precarity--Desmond.pptx
4.16.24 Poverty and Precarity--Desmond.pptxmary850239
 
Grade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdf
Grade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdfGrade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdf
Grade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdfJemuel Francisco
 
ICS2208 Lecture6 Notes for SL spaces.pdf
ICS2208 Lecture6 Notes for SL spaces.pdfICS2208 Lecture6 Notes for SL spaces.pdf
ICS2208 Lecture6 Notes for SL spaces.pdfVanessa Camilleri
 
Expanded definition: technical and operational
Expanded definition: technical and operationalExpanded definition: technical and operational
Expanded definition: technical and operationalssuser3e220a
 
31 ĐỀ THI THỬ VÀO LỚP 10 - TIẾNG ANH - FORM MỚI 2025 - 40 CÂU HỎI - BÙI VĂN V...
31 ĐỀ THI THỬ VÀO LỚP 10 - TIẾNG ANH - FORM MỚI 2025 - 40 CÂU HỎI - BÙI VĂN V...31 ĐỀ THI THỬ VÀO LỚP 10 - TIẾNG ANH - FORM MỚI 2025 - 40 CÂU HỎI - BÙI VĂN V...
31 ĐỀ THI THỬ VÀO LỚP 10 - TIẾNG ANH - FORM MỚI 2025 - 40 CÂU HỎI - BÙI VĂN V...Nguyen Thanh Tu Collection
 
Using Grammatical Signals Suitable to Patterns of Idea Development
Using Grammatical Signals Suitable to Patterns of Idea DevelopmentUsing Grammatical Signals Suitable to Patterns of Idea Development
Using Grammatical Signals Suitable to Patterns of Idea Developmentchesterberbo7
 
Q-Factor HISPOL Quiz-6th April 2024, Quiz Club NITW
Q-Factor HISPOL Quiz-6th April 2024, Quiz Club NITWQ-Factor HISPOL Quiz-6th April 2024, Quiz Club NITW
Q-Factor HISPOL Quiz-6th April 2024, Quiz Club NITWQuiz Club NITW
 
How to Make a Duplicate of Your Odoo 17 Database
How to Make a Duplicate of Your Odoo 17 DatabaseHow to Make a Duplicate of Your Odoo 17 Database
How to Make a Duplicate of Your Odoo 17 DatabaseCeline George
 

Recently uploaded (20)

INCLUSIVE EDUCATION PRACTICES FOR TEACHERS AND TRAINERS.pptx
INCLUSIVE EDUCATION PRACTICES FOR TEACHERS AND TRAINERS.pptxINCLUSIVE EDUCATION PRACTICES FOR TEACHERS AND TRAINERS.pptx
INCLUSIVE EDUCATION PRACTICES FOR TEACHERS AND TRAINERS.pptx
 
Reading and Writing Skills 11 quarter 4 melc 1
Reading and Writing Skills 11 quarter 4 melc 1Reading and Writing Skills 11 quarter 4 melc 1
Reading and Writing Skills 11 quarter 4 melc 1
 
Faculty Profile prashantha K EEE dept Sri Sairam college of Engineering
Faculty Profile prashantha K EEE dept Sri Sairam college of EngineeringFaculty Profile prashantha K EEE dept Sri Sairam college of Engineering
Faculty Profile prashantha K EEE dept Sri Sairam college of Engineering
 
CHEST Proprioceptive neuromuscular facilitation.pptx
CHEST Proprioceptive neuromuscular facilitation.pptxCHEST Proprioceptive neuromuscular facilitation.pptx
CHEST Proprioceptive neuromuscular facilitation.pptx
 
CLASSIFICATION OF ANTI - CANCER DRUGS.pptx
CLASSIFICATION OF ANTI - CANCER DRUGS.pptxCLASSIFICATION OF ANTI - CANCER DRUGS.pptx
CLASSIFICATION OF ANTI - CANCER DRUGS.pptx
 
Oppenheimer Film Discussion for Philosophy and Film
Oppenheimer Film Discussion for Philosophy and FilmOppenheimer Film Discussion for Philosophy and Film
Oppenheimer Film Discussion for Philosophy and Film
 
Mattingly "AI & Prompt Design: Large Language Models"
Mattingly "AI & Prompt Design: Large Language Models"Mattingly "AI & Prompt Design: Large Language Models"
Mattingly "AI & Prompt Design: Large Language Models"
 
How to Fix XML SyntaxError in Odoo the 17
How to Fix XML SyntaxError in Odoo the 17How to Fix XML SyntaxError in Odoo the 17
How to Fix XML SyntaxError in Odoo the 17
 
Indexing Structures in Database Management system.pdf
Indexing Structures in Database Management system.pdfIndexing Structures in Database Management system.pdf
Indexing Structures in Database Management system.pdf
 
Sulphonamides, mechanisms and their uses
Sulphonamides, mechanisms and their usesSulphonamides, mechanisms and their uses
Sulphonamides, mechanisms and their uses
 
4.16.24 21st Century Movements for Black Lives.pptx
4.16.24 21st Century Movements for Black Lives.pptx4.16.24 21st Century Movements for Black Lives.pptx
4.16.24 21st Century Movements for Black Lives.pptx
 
Daily Lesson Plan in Mathematics Quarter 4
Daily Lesson Plan in Mathematics Quarter 4Daily Lesson Plan in Mathematics Quarter 4
Daily Lesson Plan in Mathematics Quarter 4
 
4.16.24 Poverty and Precarity--Desmond.pptx
4.16.24 Poverty and Precarity--Desmond.pptx4.16.24 Poverty and Precarity--Desmond.pptx
4.16.24 Poverty and Precarity--Desmond.pptx
 
Grade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdf
Grade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdfGrade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdf
Grade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdf
 
ICS2208 Lecture6 Notes for SL spaces.pdf
ICS2208 Lecture6 Notes for SL spaces.pdfICS2208 Lecture6 Notes for SL spaces.pdf
ICS2208 Lecture6 Notes for SL spaces.pdf
 
Expanded definition: technical and operational
Expanded definition: technical and operationalExpanded definition: technical and operational
Expanded definition: technical and operational
 
31 ĐỀ THI THỬ VÀO LỚP 10 - TIẾNG ANH - FORM MỚI 2025 - 40 CÂU HỎI - BÙI VĂN V...
31 ĐỀ THI THỬ VÀO LỚP 10 - TIẾNG ANH - FORM MỚI 2025 - 40 CÂU HỎI - BÙI VĂN V...31 ĐỀ THI THỬ VÀO LỚP 10 - TIẾNG ANH - FORM MỚI 2025 - 40 CÂU HỎI - BÙI VĂN V...
31 ĐỀ THI THỬ VÀO LỚP 10 - TIẾNG ANH - FORM MỚI 2025 - 40 CÂU HỎI - BÙI VĂN V...
 
Using Grammatical Signals Suitable to Patterns of Idea Development
Using Grammatical Signals Suitable to Patterns of Idea DevelopmentUsing Grammatical Signals Suitable to Patterns of Idea Development
Using Grammatical Signals Suitable to Patterns of Idea Development
 
Q-Factor HISPOL Quiz-6th April 2024, Quiz Club NITW
Q-Factor HISPOL Quiz-6th April 2024, Quiz Club NITWQ-Factor HISPOL Quiz-6th April 2024, Quiz Club NITW
Q-Factor HISPOL Quiz-6th April 2024, Quiz Club NITW
 
How to Make a Duplicate of Your Odoo 17 Database
How to Make a Duplicate of Your Odoo 17 DatabaseHow to Make a Duplicate of Your Odoo 17 Database
How to Make a Duplicate of Your Odoo 17 Database
 

String c

  • 1. Lectures on Busy Bee Workshop 1 Busy Bee Workshop – Session VIBusy Bee Workshop – Session VI This session Outline String String Manipulation Functions String Programs
  • 2. Lectures on Busy Bee Workshop 2 String in CString in C Sequence of characters is called string. In C, a string constant is a sequence of characters enclosed in double quotes. Examples: “C Programming” “SVN College” “3/390 Nehru Street” “45”
  • 3. Lectures on Busy Bee Workshop 3 String in C - ImplementationString in C - Implementation • C implements the stringstring data structure using arrays of type char. • We have already used the string extensively. – printf(“This program is terminated!n”); – #define ERR_Message “Error!!” • Since stringstring is an array, the declaration of a string is the same as declaring a char array. – char string_var[30]; – char string_var[20] = “Initial value”;
  • 4. Lectures on Busy Bee Workshop 4 String in C – Memory StorageString in C – Memory Storage • The string is always ended with a nullnull charactercharacter ‘0’‘0’. • The characters after the null character are ignored. • e.g., char str[20] = “Initial value”; n i t i a l v a l u e ? ? …I 00 [0] [13]
  • 5. Lectures on Busy Bee Workshop 5 String in C – Arrays of StringsString in C – Arrays of Strings • An array of strings is a two-dimensional array of characters in which each row is one string. – char names[People][Length]; – char names[10][25]; – char month[5][10] = {“January”, “February”, “March”, “April”, “May”};
  • 6. Lectures on Busy Bee Workshop 6 String in C – Character vs. StringString in C – Character vs. String
  • 7. Lectures on Busy Bee Workshop 7 String in C – Input/OutputString in C – Input/Output • The placeholder %s%s is used to represent string arguments in printf and scanf. • Example: char message1[12] = "Hello world"; printf(“%s”,message1); message1: char message2[12]; scanf(“%s”,message2); // type "Hello" as input message2: H e l l o w o r l d 0 H e l l o 0 ? ? ? ? ? ?
  • 8. Lectures on Busy Bee Workshop 8 String in C – Right and Left Justification of StringsString in C – Right and Left Justification of Strings • The string can be right-justified by placing a positive number in the placeholder. – printf(“%8s%8s”, str); • The string can be left-justified by placing a negative number in the placeholder. – Printf(“%-8s%-8s”, str);
  • 9. Lectures on Busy Bee Workshop 9 String in C – Example programString in C – Example program
  • 10. Lectures on Busy Bee Workshop 10 String in C – Library FunctionsString in C – Library Functions • The string can not be copied by the assignment operator ‘=’. – e..g, “str = “Test String”” is not valid. • C provides string manipulating functions in the “string.h” library. – The list of these functions can be found in the next slide.
  • 11. Lectures on Busy Bee Workshop 11 String in C – Library FunctionsString in C – Library Functions Function Purpose Example strcpy Makes a copy of a string strcpy(s1, “Hi”); strcat Appends a string to the end of another string strcat(s1, “more”); strcmp Compare two strings alphabetically strcmp(s1, “Hu”); strlen Returns the number of characters in a string strlen(“Hi”) returns 2. strtok Breaks a string into tokens by delimiters. strtok(“Hi, Chao”, “ ,”);
  • 12. Lectures on Busy Bee Workshop 12 String in C – Library FunctionsString in C – Library Functions Function Purpose Example Strncpy Copy the specified number of characters strncpy(s1, “SVN”,2); Strncmp Compare two string upto given n character strncmp(“mo”, “more”,2); Stricmp Compare two strings alphabetically without case sensitivity. stricmp(“hu”, “Hu”); strlwr Converts string to all lowercase strlwr(“Hi”) returns hi. strupr Converts s to all uppercase strupr(“Hi”);
  • 13. Lectures on Busy Bee Workshop 13 String in C – Library FunctionsString in C – Library Functions Function Purpose Example Strncat Appends a string to the end of another string up to n characters strncat(s1, “more”,2); Strrev Reverses all characters in s1 (except for the terminating null) strrev(s1, “more”);
  • 14. Lectures on Busy Bee Workshop 14 String in C – Example program (Library Function)String in C – Example program (Library Function)