SlideShare ist ein Scribd-Unternehmen logo
1 von 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

Weitere ähnliche Inhalte

Was ist angesagt?

Stacks Implementation and Examples
Stacks Implementation and ExamplesStacks Implementation and Examples
Stacks Implementation and Examples
greatqadirgee4u
 

Was ist angesagt? (20)

Strings in C language
Strings in C languageStrings in C language
Strings in C language
 
C string
C stringC string
C string
 
String functions in C
String functions in CString functions in C
String functions in C
 
Strings
StringsStrings
Strings
 
Polymorphism in c++(ppt)
Polymorphism in c++(ppt)Polymorphism in c++(ppt)
Polymorphism in c++(ppt)
 
10. switch case
10. switch case10. switch case
10. switch case
 
Arrays and Strings
Arrays and Strings Arrays and Strings
Arrays and Strings
 
Programming in c Arrays
Programming in c ArraysProgramming in c Arrays
Programming in c Arrays
 
Stacks Implementation and Examples
Stacks Implementation and ExamplesStacks Implementation and Examples
Stacks Implementation and Examples
 
Pointers
PointersPointers
Pointers
 
Operation on string presentation
Operation on string presentationOperation on string presentation
Operation on string presentation
 
Handling of character strings C programming
Handling of character strings C programmingHandling of character strings C programming
Handling of character strings C programming
 
Java String Handling
Java String HandlingJava String Handling
Java String Handling
 
File handling in c
File handling in cFile handling in c
File handling in c
 
C-Programming C LIBRARIES AND USER DEFINED LIBRARIES.pptx
C-Programming  C LIBRARIES AND USER DEFINED LIBRARIES.pptxC-Programming  C LIBRARIES AND USER DEFINED LIBRARIES.pptx
C-Programming C LIBRARIES AND USER DEFINED LIBRARIES.pptx
 
String In C Language
String In C Language String In C Language
String In C Language
 
C Programming Unit-1
C Programming Unit-1C Programming Unit-1
C Programming Unit-1
 
Java Strings
Java StringsJava Strings
Java Strings
 
Input output statement in C
Input output statement in CInput output statement in C
Input output statement in C
 
File handling in c
File handling in cFile handling in c
File handling in c
 

Andere mochten auch (12)

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
 
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
 

Ähnlich wie String c

5 2. string processing
5 2. string processing5 2. string processing
5 2. string processing
웅식 전
 
CPSTRINGSARGAVISTRINGS.PPT
CPSTRINGSARGAVISTRINGS.PPTCPSTRINGSARGAVISTRINGS.PPT
CPSTRINGSARGAVISTRINGS.PPT
Sasideepa
 

Ähnlich wie 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
 
Character Array and String
Character Array and StringCharacter Array and String
Character Array and String
 
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++
 

Mehr von 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
 

Kürzlich hochgeladen

Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in DelhiRussian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
kauryashika82
 
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
ZurliaSoop
 

Kürzlich hochgeladen (20)

Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdf
 
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in DelhiRussian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
 
Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)
 
This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.
 
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxBasic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
 
Sociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning ExhibitSociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning Exhibit
 
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
 
Third Battle of Panipat detailed notes.pptx
Third Battle of Panipat detailed notes.pptxThird Battle of Panipat detailed notes.pptx
Third Battle of Panipat detailed notes.pptx
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy Consulting
 
On National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsOn National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan Fellows
 
ComPTIA Overview | Comptia Security+ Book SY0-701
ComPTIA Overview | Comptia Security+ Book SY0-701ComPTIA Overview | Comptia Security+ Book SY0-701
ComPTIA Overview | Comptia Security+ Book SY0-701
 
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
 
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
 
Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024
 
Spatium Project Simulation student brief
Spatium Project Simulation student briefSpatium Project Simulation student brief
Spatium Project Simulation student brief
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introduction
 
Python Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxPython Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docx
 
Unit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptxUnit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptx
 
Magic bus Group work1and 2 (Team 3).pptx
Magic bus Group work1and 2 (Team 3).pptxMagic bus Group work1and 2 (Team 3).pptx
Magic bus Group work1and 2 (Team 3).pptx
 
How to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POSHow to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POS
 

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)