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

PPT
Strings
PPTX
PDF
Python functions
PPTX
C programming - String
PPT
Array in c
PPTX
Strings in C language
PPTX
String in c programming
PPT
structure and union
Strings
Python functions
C programming - String
Array in c
Strings in C language
String in c programming
structure and union

What's hot (20)

PDF
Character Array and String
DOC
Arrays and Strings
PPTX
User defined functions in C
PPTX
Introduction to-python
PPTX
Conditional Statement in C Language
PPTX
Loops in Python
PDF
Python basic
PPTX
C++ string
PPTX
Stream classes in C++
PPT
Operators in C Programming
PPTX
Managing input and output operations in c
PPT
File handling in c
PPTX
Python | What is Python | History of Python | Python Tutorial
PPTX
Array and string
PPTX
Dynamic memory allocation in c
PDF
Python Programming
PPTX
Handling of character strings C programming
PDF
Operators in python
PPTX
Data structure - Graph
Character Array and String
Arrays and Strings
User defined functions in C
Introduction to-python
Conditional Statement in C Language
Loops in Python
Python basic
C++ string
Stream classes in C++
Operators in C Programming
Managing input and output operations in c
File handling in c
Python | What is Python | History of Python | Python Tutorial
Array and string
Dynamic memory allocation in c
Python Programming
Handling of character strings C programming
Operators in python
Data structure - Graph
Ad

Viewers also liked (14)

DOC
String in c
PPTX
Loops Basics
PPTX
Function in c
PPT
Structure in C
PPTX
Arrays in C language
PPT
Structure c
PPT
Structure of a C program
PPTX
Strings in C
PPTX
Loops in C
PPTX
Loops in C Programming
PPTX
Array in c language
PPTX
Functions in C
PPTX
Function in C program
String in c
Loops Basics
Function in c
Structure in C
Arrays in C language
Structure c
Structure of a C program
Strings in C
Loops in C
Loops in C Programming
Array in c language
Functions in C
Function in C program
Ad

Similar to String c (20)

PPT
Operation on string presentation
PDF
5 2. string processing
PPT
Strings in c
PPTX
24_2-String and String Library.pptx
PPTX
introduction to strings in c programming
PPTX
All_About_Strings_in_C_Programming.pptxn
PPTX
fundamentals of c programming_String.pptx
PDF
[ITP - Lecture 17] Strings in C/C++
PPTX
unit-5 String Math Date Time AI presentation
PPTX
Week6_P_String.pptx
PDF
14-Strings-In-Python strings with oops .pdf
PPTX
Strings CPU GTU
PPTX
String In C Language
PPT
Strings
PPTX
COm1407: Character & Strings
PPT
lecture5.ppt
PDF
Matlab strings
Operation on string presentation
5 2. string processing
Strings in c
24_2-String and String Library.pptx
introduction to strings in c programming
All_About_Strings_in_C_Programming.pptxn
fundamentals of c programming_String.pptx
[ITP - Lecture 17] Strings in C/C++
unit-5 String Math Date Time AI presentation
Week6_P_String.pptx
14-Strings-In-Python strings with oops .pdf
Strings CPU GTU
String In C Language
Strings
COm1407: Character & Strings
lecture5.ppt
Matlab strings

More from thirumalaikumar3 (8)

PPT
Data type in c
PPT
Control flow in c
PPTX
C function
PDF
Coper in C
PPTX
PPT
File handling in c
PPT
File handling-c programming language
PPT
Data type2 c
Data type in c
Control flow in c
C function
Coper in C
File handling in c
File handling-c programming language
Data type2 c

Recently uploaded (20)

PDF
Black Hat USA 2025 - Micro ICS Summit - ICS/OT Threat Landscape
PDF
Supply Chain Operations Speaking Notes -ICLT Program
PDF
Microbial disease of the cardiovascular and lymphatic systems
PPTX
school management -TNTEU- B.Ed., Semester II Unit 1.pptx
PDF
2.FourierTransform-ShortQuestionswithAnswers.pdf
PDF
O5-L3 Freight Transport Ops (International) V1.pdf
PDF
Weekly quiz Compilation Jan -July 25.pdf
PDF
O7-L3 Supply Chain Operations - ICLT Program
PPTX
Orientation - ARALprogram of Deped to the Parents.pptx
PPTX
Introduction-to-Literarature-and-Literary-Studies-week-Prelim-coverage.pptx
PPTX
Pharmacology of Heart Failure /Pharmacotherapy of CHF
PDF
VCE English Exam - Section C Student Revision Booklet
PPTX
Final Presentation General Medicine 03-08-2024.pptx
PDF
Computing-Curriculum for Schools in Ghana
PDF
RMMM.pdf make it easy to upload and study
PDF
GENETICS IN BIOLOGY IN SECONDARY LEVEL FORM 3
PDF
Chapter 2 Heredity, Prenatal Development, and Birth.pdf
PPTX
202450812 BayCHI UCSC-SV 20250812 v17.pptx
PDF
FourierSeries-QuestionsWithAnswers(Part-A).pdf
PPTX
Cell Types and Its function , kingdom of life
Black Hat USA 2025 - Micro ICS Summit - ICS/OT Threat Landscape
Supply Chain Operations Speaking Notes -ICLT Program
Microbial disease of the cardiovascular and lymphatic systems
school management -TNTEU- B.Ed., Semester II Unit 1.pptx
2.FourierTransform-ShortQuestionswithAnswers.pdf
O5-L3 Freight Transport Ops (International) V1.pdf
Weekly quiz Compilation Jan -July 25.pdf
O7-L3 Supply Chain Operations - ICLT Program
Orientation - ARALprogram of Deped to the Parents.pptx
Introduction-to-Literarature-and-Literary-Studies-week-Prelim-coverage.pptx
Pharmacology of Heart Failure /Pharmacotherapy of CHF
VCE English Exam - Section C Student Revision Booklet
Final Presentation General Medicine 03-08-2024.pptx
Computing-Curriculum for Schools in Ghana
RMMM.pdf make it easy to upload and study
GENETICS IN BIOLOGY IN SECONDARY LEVEL FORM 3
Chapter 2 Heredity, Prenatal Development, and Birth.pdf
202450812 BayCHI UCSC-SV 20250812 v17.pptx
FourierSeries-QuestionsWithAnswers(Part-A).pdf
Cell Types and Its function , kingdom of life

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)