SlideShare a Scribd company logo
Today Our Topic is
‘’STRING”
Introduction
 Strings are array of characters i.e. they are characters
arranged one after another in memory. Thus, a character
array is called string.
 Each character within the string is stored within one
element of the array successively.
 A string is always terminated by a null character (i.e.
slash zero 0).
Arrays and Strings…
 Operations performed on character strings include:
 Reading and writing strings
 Copying one string to another
 Combining strings together
 Comparing strings for equality
 Extracting a portion of a string
 A string variable is declared as an array of characters.
 Syntax:
char string_name[size];
 E.g. char name[20];
 When the compiler assigns a character string to a character array, it
automatically supplies a null character (‘0’) at the end of the string
Initializing String Variables
 Strings are initialized in either of the following two forms:
char name[4]={‘R’,‘A’,‘M’, ‘0’};
char name[]={‘R’,‘A’,‘M’, ‘0’};
char name[4]=“RAM”;
char name[]=“RAM”;
 When we initialize a character array by listing its elements, the null terminator
or the size of the array must be provided explicitly.
R A M 0
name[0] name[1] name[2] name[3]
Reading and displaying Strings
 It can be done manually.
Using printf() and scanf()
Using gets() and puts()
Passing String to function
String handling functions
 Strings need to be manipulated by programmer.
 It can be done manually but is time consuming.
Counting length of the string
#include <stdio.h>
void main()
{
char input_string[50];
int i=0, length=0;
clrscr();
printf("nEnter your text:t");
gets(input_string);
while(input_string[i]!='0')
{
length++;
i++;
}
printf("nThe length of your text is: %d character(s)", length);
}
 There are various string handling functions define in
string.h some of them are:
void main()
{
char string[25];
clrscr();
printf("nInput string to be reversed:");
gets(string);
strrev(string);
printf("nThe reversed string is: %s", string);
getch();
}
13
Using Revers Function “Strrev()”
Arrays of Strings
 String is array of characters.
 Thus an array of string is 2-D array of characters.
 E.g.
char names[5][10];
 Here, names[5][10] means 5 names having 10 characters
each.
1
4
void main()
{
char names[5][10];
int i;
clrscr();
printf("nEnter name of 5 persons:");
for(i=0;i<5;i++)
scanf("%s", names[i]);
printf("nThe names are:");
for(i=0;i<5;i++)
printf("n%s", names[i]);
getch();
}
1
5
Ad

More Related Content

What's hot (20)

Strings in C
Strings in CStrings in C
Strings in C
Kamal Acharya
 
Strings
StringsStrings
Strings
Nilesh Dalvi
 
Strings Functions in C Programming
Strings Functions in C ProgrammingStrings Functions in C Programming
Strings Functions in C Programming
DevoAjit Gupta
 
Strings
StringsStrings
Strings
Mitali Chugh
 
Strings in c
Strings in cStrings in c
Strings in c
vampugani
 
String c
String cString c
String c
thirumalaikumar3
 
Strinng Classes in c++
Strinng Classes in c++Strinng Classes in c++
Strinng Classes in c++
Vikash Dhal
 
String.ppt
String.pptString.ppt
String.ppt
ajeela mushtaq
 
Operation on string presentation
Operation on string presentationOperation on string presentation
Operation on string presentation
Aliul Kadir Akib
 
Handling of character strings C programming
Handling of character strings C programmingHandling of character strings C programming
Handling of character strings C programming
Appili Vamsi Krishna
 
Array and string
Array and stringArray and string
Array and string
prashant chelani
 
Strings
StringsStrings
Strings
Michael Gordon
 
05 c++-strings
05 c++-strings05 c++-strings
05 c++-strings
Kelly Swanson
 
String functions in C
String functions in CString functions in C
String functions in C
baabtra.com - No. 1 supplier of quality freshers
 
Arrays and strings in c++
Arrays and strings in c++Arrays and strings in c++
Arrays and strings in c++
GC University Faisalabad
 
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
Rai University
 
C programming - String
C programming - StringC programming - String
C programming - String
Achyut Devkota
 
Chap 8(strings)
Chap 8(strings)Chap 8(strings)
Chap 8(strings)
Bangabandhu Sheikh Mujibur Rahman Science and Technology University
 
C++ string
C++ stringC++ string
C++ string
Dheenadayalan18
 
Implementation Of String Functions In C
Implementation Of String Functions In CImplementation Of String Functions In C
Implementation Of String Functions In C
Fazila Sadia
 

Similar to Strings in programming tutorial. (20)

strings-150319180934-conversion-gate01.pdf
strings-150319180934-conversion-gate01.pdfstrings-150319180934-conversion-gate01.pdf
strings-150319180934-conversion-gate01.pdf
HEMAHEMS5
 
Programming in C - Fundamental Study of Strings
Programming in C - Fundamental Study of  StringsProgramming in C - Fundamental Study of  Strings
Programming in C - Fundamental Study of Strings
Dr. Chandrakant Divate
 
[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++
Muhammad Hammad Waseem
 
String notes
String notesString notes
String notes
Prasadu Peddi
 
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
 
introduction to strings in c programming
introduction to strings in c programmingintroduction to strings in c programming
introduction to strings in c programming
mikeymanjiro2090
 
C Programming Unit-3
C Programming Unit-3C Programming Unit-3
C Programming Unit-3
Vikram Nandini
 
STRINGS IN C MRS.SOWMYA JYOTHI.pdf
STRINGS IN C MRS.SOWMYA JYOTHI.pdfSTRINGS IN C MRS.SOWMYA JYOTHI.pdf
STRINGS IN C MRS.SOWMYA JYOTHI.pdf
SowmyaJyothi3
 
Array &strings
Array &stringsArray &strings
Array &strings
UMA PARAMESWARI
 
Strings in c mrs.sowmya jyothi
Strings in c mrs.sowmya jyothiStrings in c mrs.sowmya jyothi
Strings in c mrs.sowmya jyothi
Sowmya Jyothi
 
Strings In C and its syntax and uses .ppt
Strings In C and its syntax and uses .pptStrings In C and its syntax and uses .ppt
Strings In C and its syntax and uses .ppt
fallengaming1606
 
Lecture 17 - Strings
Lecture 17 - StringsLecture 17 - Strings
Lecture 17 - Strings
Md. Imran Hossain Showrov
 
14 strings
14 strings14 strings
14 strings
Rohit Shrivastava
 
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
 
Week6_P_String.pptx
Week6_P_String.pptxWeek6_P_String.pptx
Week6_P_String.pptx
OluwafolakeOjo
 
Module-2_Strings concepts in c programming
Module-2_Strings concepts in c programmingModule-2_Strings concepts in c programming
Module-2_Strings concepts in c programming
CHAITRAB29
 
String
StringString
String
Amarjith C K
 
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
 
Lesson in Strings for C Programming Lessons
Lesson in Strings for C Programming LessonsLesson in Strings for C Programming Lessons
Lesson in Strings for C Programming Lessons
JamesChristianGadian
 
string function with example...................
string function with example...................string function with example...................
string function with example...................
NishantsrivastavaV
 
strings-150319180934-conversion-gate01.pdf
strings-150319180934-conversion-gate01.pdfstrings-150319180934-conversion-gate01.pdf
strings-150319180934-conversion-gate01.pdf
HEMAHEMS5
 
Programming in C - Fundamental Study of Strings
Programming in C - Fundamental Study of  StringsProgramming in C - Fundamental Study of  Strings
Programming in C - Fundamental Study of Strings
Dr. Chandrakant Divate
 
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
 
introduction to strings in c programming
introduction to strings in c programmingintroduction to strings in c programming
introduction to strings in c programming
mikeymanjiro2090
 
STRINGS IN C MRS.SOWMYA JYOTHI.pdf
STRINGS IN C MRS.SOWMYA JYOTHI.pdfSTRINGS IN C MRS.SOWMYA JYOTHI.pdf
STRINGS IN C MRS.SOWMYA JYOTHI.pdf
SowmyaJyothi3
 
Strings in c mrs.sowmya jyothi
Strings in c mrs.sowmya jyothiStrings in c mrs.sowmya jyothi
Strings in c mrs.sowmya jyothi
Sowmya Jyothi
 
Strings In C and its syntax and uses .ppt
Strings In C and its syntax and uses .pptStrings In C and its syntax and uses .ppt
Strings In C and its syntax and uses .ppt
fallengaming1606
 
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
 
Module-2_Strings concepts in c programming
Module-2_Strings concepts in c programmingModule-2_Strings concepts in c programming
Module-2_Strings concepts in c programming
CHAITRAB29
 
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
 
Lesson in Strings for C Programming Lessons
Lesson in Strings for C Programming LessonsLesson in Strings for C Programming Lessons
Lesson in Strings for C Programming Lessons
JamesChristianGadian
 
string function with example...................
string function with example...................string function with example...................
string function with example...................
NishantsrivastavaV
 
Ad

More from Samsil Arefin (20)

Transmission Control Protocol and User Datagram protocol
Transmission Control Protocol and User Datagram protocolTransmission Control Protocol and User Datagram protocol
Transmission Control Protocol and User Datagram protocol
Samsil Arefin
 
Evolution Phylogenetic
Evolution PhylogeneticEvolution Phylogenetic
Evolution Phylogenetic
Samsil Arefin
 
Evolution Phylogenetic
Evolution PhylogeneticEvolution Phylogenetic
Evolution Phylogenetic
Samsil Arefin
 
Ego net facebook data analysis
Ego net facebook data analysisEgo net facebook data analysis
Ego net facebook data analysis
Samsil Arefin
 
Augmented Reality (AR)
Augmented Reality (AR)Augmented Reality (AR)
Augmented Reality (AR)
Samsil Arefin
 
Client server chat application
Client server chat applicationClient server chat application
Client server chat application
Samsil Arefin
 
Linked list searching deleting inserting
Linked list searching deleting insertingLinked list searching deleting inserting
Linked list searching deleting inserting
Samsil Arefin
 
Number theory
Number theoryNumber theory
Number theory
Samsil Arefin
 
Program to sort the n names in an alphabetical order
Program to sort the n names in an alphabetical orderProgram to sort the n names in an alphabetical order
Program to sort the n names in an alphabetical order
Samsil Arefin
 
Linked list int_data_fdata
Linked list int_data_fdataLinked list int_data_fdata
Linked list int_data_fdata
Samsil Arefin
 
Linked list Output tracing
Linked list Output tracingLinked list Output tracing
Linked list Output tracing
Samsil Arefin
 
Stack
StackStack
Stack
Samsil Arefin
 
Sorting
SortingSorting
Sorting
Samsil Arefin
 
Fundamentals of-electric-circuit
Fundamentals of-electric-circuitFundamentals of-electric-circuit
Fundamentals of-electric-circuit
Samsil Arefin
 
Cyber security
Cyber securityCyber security
Cyber security
Samsil Arefin
 
C programming
C programmingC programming
C programming
Samsil Arefin
 
Data structure lecture 1
Data structure   lecture 1Data structure   lecture 1
Data structure lecture 1
Samsil Arefin
 
Structure and union
Structure and unionStructure and union
Structure and union
Samsil Arefin
 
Structure in programming in c or c++ or c# or java
Structure in programming  in c or c++ or c# or javaStructure in programming  in c or c++ or c# or java
Structure in programming in c or c++ or c# or java
Samsil Arefin
 
String
StringString
String
Samsil Arefin
 
Transmission Control Protocol and User Datagram protocol
Transmission Control Protocol and User Datagram protocolTransmission Control Protocol and User Datagram protocol
Transmission Control Protocol and User Datagram protocol
Samsil Arefin
 
Evolution Phylogenetic
Evolution PhylogeneticEvolution Phylogenetic
Evolution Phylogenetic
Samsil Arefin
 
Evolution Phylogenetic
Evolution PhylogeneticEvolution Phylogenetic
Evolution Phylogenetic
Samsil Arefin
 
Ego net facebook data analysis
Ego net facebook data analysisEgo net facebook data analysis
Ego net facebook data analysis
Samsil Arefin
 
Augmented Reality (AR)
Augmented Reality (AR)Augmented Reality (AR)
Augmented Reality (AR)
Samsil Arefin
 
Client server chat application
Client server chat applicationClient server chat application
Client server chat application
Samsil Arefin
 
Linked list searching deleting inserting
Linked list searching deleting insertingLinked list searching deleting inserting
Linked list searching deleting inserting
Samsil Arefin
 
Program to sort the n names in an alphabetical order
Program to sort the n names in an alphabetical orderProgram to sort the n names in an alphabetical order
Program to sort the n names in an alphabetical order
Samsil Arefin
 
Linked list int_data_fdata
Linked list int_data_fdataLinked list int_data_fdata
Linked list int_data_fdata
Samsil Arefin
 
Linked list Output tracing
Linked list Output tracingLinked list Output tracing
Linked list Output tracing
Samsil Arefin
 
Fundamentals of-electric-circuit
Fundamentals of-electric-circuitFundamentals of-electric-circuit
Fundamentals of-electric-circuit
Samsil Arefin
 
Data structure lecture 1
Data structure   lecture 1Data structure   lecture 1
Data structure lecture 1
Samsil Arefin
 
Structure in programming in c or c++ or c# or java
Structure in programming  in c or c++ or c# or javaStructure in programming  in c or c++ or c# or java
Structure in programming in c or c++ or c# or java
Samsil Arefin
 
Ad

Recently uploaded (20)

Resistance measurement and cfd test on darpa subboff model
Resistance measurement and cfd test on darpa subboff modelResistance measurement and cfd test on darpa subboff model
Resistance measurement and cfd test on darpa subboff model
INDIAN INSTITUTE OF TECHNOLOGY KHARAGPUR
 
Metal alkyne complexes.pptx in chemistry
Metal alkyne complexes.pptx in chemistryMetal alkyne complexes.pptx in chemistry
Metal alkyne complexes.pptx in chemistry
mee23nu
 
RICS Membership-(The Royal Institution of Chartered Surveyors).pdf
RICS Membership-(The Royal Institution of Chartered Surveyors).pdfRICS Membership-(The Royal Institution of Chartered Surveyors).pdf
RICS Membership-(The Royal Institution of Chartered Surveyors).pdf
MohamedAbdelkader115
 
theory-slides-for react for beginners.pptx
theory-slides-for react for beginners.pptxtheory-slides-for react for beginners.pptx
theory-slides-for react for beginners.pptx
sanchezvanessa7896
 
MAQUINARIA MINAS CEMA 6th Edition (1).pdf
MAQUINARIA MINAS CEMA 6th Edition (1).pdfMAQUINARIA MINAS CEMA 6th Edition (1).pdf
MAQUINARIA MINAS CEMA 6th Edition (1).pdf
ssuser562df4
 
Data Structures_Introduction to algorithms.pptx
Data Structures_Introduction to algorithms.pptxData Structures_Introduction to algorithms.pptx
Data Structures_Introduction to algorithms.pptx
RushaliDeshmukh2
 
Compiler Design_Lexical Analysis phase.pptx
Compiler Design_Lexical Analysis phase.pptxCompiler Design_Lexical Analysis phase.pptx
Compiler Design_Lexical Analysis phase.pptx
RushaliDeshmukh2
 
ELectronics Boards & Product Testing_Shiju.pdf
ELectronics Boards & Product Testing_Shiju.pdfELectronics Boards & Product Testing_Shiju.pdf
ELectronics Boards & Product Testing_Shiju.pdf
Shiju Jacob
 
fluke dealers in bangalore..............
fluke dealers in bangalore..............fluke dealers in bangalore..............
fluke dealers in bangalore..............
Haresh Vaswani
 
Data Structures_Linear data structures Linked Lists.pptx
Data Structures_Linear data structures Linked Lists.pptxData Structures_Linear data structures Linked Lists.pptx
Data Structures_Linear data structures Linked Lists.pptx
RushaliDeshmukh2
 
"Feed Water Heaters in Thermal Power Plants: Types, Working, and Efficiency G...
"Feed Water Heaters in Thermal Power Plants: Types, Working, and Efficiency G..."Feed Water Heaters in Thermal Power Plants: Types, Working, and Efficiency G...
"Feed Water Heaters in Thermal Power Plants: Types, Working, and Efficiency G...
Infopitaara
 
Mathematical foundation machine learning.pdf
Mathematical foundation machine learning.pdfMathematical foundation machine learning.pdf
Mathematical foundation machine learning.pdf
TalhaShahid49
 
Artificial Intelligence introduction.pptx
Artificial Intelligence introduction.pptxArtificial Intelligence introduction.pptx
Artificial Intelligence introduction.pptx
DrMarwaElsherif
 
Artificial Intelligence (AI) basics.pptx
Artificial Intelligence (AI) basics.pptxArtificial Intelligence (AI) basics.pptx
Artificial Intelligence (AI) basics.pptx
aditichinar
 
ADVXAI IN MALWARE ANALYSIS FRAMEWORK: BALANCING EXPLAINABILITY WITH SECURITY
ADVXAI IN MALWARE ANALYSIS FRAMEWORK: BALANCING EXPLAINABILITY WITH SECURITYADVXAI IN MALWARE ANALYSIS FRAMEWORK: BALANCING EXPLAINABILITY WITH SECURITY
ADVXAI IN MALWARE ANALYSIS FRAMEWORK: BALANCING EXPLAINABILITY WITH SECURITY
ijscai
 
DT REPORT by Tech titan GROUP to introduce the subject design Thinking
DT REPORT by Tech titan GROUP to introduce the subject design ThinkingDT REPORT by Tech titan GROUP to introduce the subject design Thinking
DT REPORT by Tech titan GROUP to introduce the subject design Thinking
DhruvChotaliya2
 
some basics electrical and electronics knowledge
some basics electrical and electronics knowledgesome basics electrical and electronics knowledge
some basics electrical and electronics knowledge
nguyentrungdo88
 
The Gaussian Process Modeling Module in UQLab
The Gaussian Process Modeling Module in UQLabThe Gaussian Process Modeling Module in UQLab
The Gaussian Process Modeling Module in UQLab
Journal of Soft Computing in Civil Engineering
 
new ppt artificial intelligence historyyy
new ppt artificial intelligence historyyynew ppt artificial intelligence historyyy
new ppt artificial intelligence historyyy
PianoPianist
 
Data Structures_Searching and Sorting.pptx
Data Structures_Searching and Sorting.pptxData Structures_Searching and Sorting.pptx
Data Structures_Searching and Sorting.pptx
RushaliDeshmukh2
 
Metal alkyne complexes.pptx in chemistry
Metal alkyne complexes.pptx in chemistryMetal alkyne complexes.pptx in chemistry
Metal alkyne complexes.pptx in chemistry
mee23nu
 
RICS Membership-(The Royal Institution of Chartered Surveyors).pdf
RICS Membership-(The Royal Institution of Chartered Surveyors).pdfRICS Membership-(The Royal Institution of Chartered Surveyors).pdf
RICS Membership-(The Royal Institution of Chartered Surveyors).pdf
MohamedAbdelkader115
 
theory-slides-for react for beginners.pptx
theory-slides-for react for beginners.pptxtheory-slides-for react for beginners.pptx
theory-slides-for react for beginners.pptx
sanchezvanessa7896
 
MAQUINARIA MINAS CEMA 6th Edition (1).pdf
MAQUINARIA MINAS CEMA 6th Edition (1).pdfMAQUINARIA MINAS CEMA 6th Edition (1).pdf
MAQUINARIA MINAS CEMA 6th Edition (1).pdf
ssuser562df4
 
Data Structures_Introduction to algorithms.pptx
Data Structures_Introduction to algorithms.pptxData Structures_Introduction to algorithms.pptx
Data Structures_Introduction to algorithms.pptx
RushaliDeshmukh2
 
Compiler Design_Lexical Analysis phase.pptx
Compiler Design_Lexical Analysis phase.pptxCompiler Design_Lexical Analysis phase.pptx
Compiler Design_Lexical Analysis phase.pptx
RushaliDeshmukh2
 
ELectronics Boards & Product Testing_Shiju.pdf
ELectronics Boards & Product Testing_Shiju.pdfELectronics Boards & Product Testing_Shiju.pdf
ELectronics Boards & Product Testing_Shiju.pdf
Shiju Jacob
 
fluke dealers in bangalore..............
fluke dealers in bangalore..............fluke dealers in bangalore..............
fluke dealers in bangalore..............
Haresh Vaswani
 
Data Structures_Linear data structures Linked Lists.pptx
Data Structures_Linear data structures Linked Lists.pptxData Structures_Linear data structures Linked Lists.pptx
Data Structures_Linear data structures Linked Lists.pptx
RushaliDeshmukh2
 
"Feed Water Heaters in Thermal Power Plants: Types, Working, and Efficiency G...
"Feed Water Heaters in Thermal Power Plants: Types, Working, and Efficiency G..."Feed Water Heaters in Thermal Power Plants: Types, Working, and Efficiency G...
"Feed Water Heaters in Thermal Power Plants: Types, Working, and Efficiency G...
Infopitaara
 
Mathematical foundation machine learning.pdf
Mathematical foundation machine learning.pdfMathematical foundation machine learning.pdf
Mathematical foundation machine learning.pdf
TalhaShahid49
 
Artificial Intelligence introduction.pptx
Artificial Intelligence introduction.pptxArtificial Intelligence introduction.pptx
Artificial Intelligence introduction.pptx
DrMarwaElsherif
 
Artificial Intelligence (AI) basics.pptx
Artificial Intelligence (AI) basics.pptxArtificial Intelligence (AI) basics.pptx
Artificial Intelligence (AI) basics.pptx
aditichinar
 
ADVXAI IN MALWARE ANALYSIS FRAMEWORK: BALANCING EXPLAINABILITY WITH SECURITY
ADVXAI IN MALWARE ANALYSIS FRAMEWORK: BALANCING EXPLAINABILITY WITH SECURITYADVXAI IN MALWARE ANALYSIS FRAMEWORK: BALANCING EXPLAINABILITY WITH SECURITY
ADVXAI IN MALWARE ANALYSIS FRAMEWORK: BALANCING EXPLAINABILITY WITH SECURITY
ijscai
 
DT REPORT by Tech titan GROUP to introduce the subject design Thinking
DT REPORT by Tech titan GROUP to introduce the subject design ThinkingDT REPORT by Tech titan GROUP to introduce the subject design Thinking
DT REPORT by Tech titan GROUP to introduce the subject design Thinking
DhruvChotaliya2
 
some basics electrical and electronics knowledge
some basics electrical and electronics knowledgesome basics electrical and electronics knowledge
some basics electrical and electronics knowledge
nguyentrungdo88
 
new ppt artificial intelligence historyyy
new ppt artificial intelligence historyyynew ppt artificial intelligence historyyy
new ppt artificial intelligence historyyy
PianoPianist
 
Data Structures_Searching and Sorting.pptx
Data Structures_Searching and Sorting.pptxData Structures_Searching and Sorting.pptx
Data Structures_Searching and Sorting.pptx
RushaliDeshmukh2
 

Strings in programming tutorial.

  • 1. Today Our Topic is ‘’STRING”
  • 2. Introduction  Strings are array of characters i.e. they are characters arranged one after another in memory. Thus, a character array is called string.  Each character within the string is stored within one element of the array successively.  A string is always terminated by a null character (i.e. slash zero 0).
  • 3. Arrays and Strings…  Operations performed on character strings include:  Reading and writing strings  Copying one string to another  Combining strings together  Comparing strings for equality  Extracting a portion of a string
  • 4.  A string variable is declared as an array of characters.  Syntax: char string_name[size];  E.g. char name[20];  When the compiler assigns a character string to a character array, it automatically supplies a null character (‘0’) at the end of the string
  • 5. Initializing String Variables  Strings are initialized in either of the following two forms: char name[4]={‘R’,‘A’,‘M’, ‘0’}; char name[]={‘R’,‘A’,‘M’, ‘0’}; char name[4]=“RAM”; char name[]=“RAM”;  When we initialize a character array by listing its elements, the null terminator or the size of the array must be provided explicitly. R A M 0 name[0] name[1] name[2] name[3]
  • 6. Reading and displaying Strings  It can be done manually.
  • 9. Passing String to function
  • 10. String handling functions  Strings need to be manipulated by programmer.  It can be done manually but is time consuming.
  • 11. Counting length of the string #include <stdio.h> void main() { char input_string[50]; int i=0, length=0; clrscr(); printf("nEnter your text:t"); gets(input_string); while(input_string[i]!='0') { length++; i++; } printf("nThe length of your text is: %d character(s)", length); }
  • 12.  There are various string handling functions define in string.h some of them are:
  • 13. void main() { char string[25]; clrscr(); printf("nInput string to be reversed:"); gets(string); strrev(string); printf("nThe reversed string is: %s", string); getch(); } 13 Using Revers Function “Strrev()”
  • 14. Arrays of Strings  String is array of characters.  Thus an array of string is 2-D array of characters.  E.g. char names[5][10];  Here, names[5][10] means 5 names having 10 characters each. 1 4
  • 15. void main() { char names[5][10]; int i; clrscr(); printf("nEnter name of 5 persons:"); for(i=0;i<5;i++) scanf("%s", names[i]); printf("nThe names are:"); for(i=0;i<5;i++) printf("n%s", names[i]); getch(); } 1 5