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

More Related Content

PPTX
Strings in C language
PPTX
String in c programming
PDF
Strings IN C
PDF
Strings in c language
PPTX
strings in c language and its importance
DOC
String in c
PDF
Character Array and String
PPTX
String C Programming
Strings in C language
String in c programming
Strings IN C
Strings in c language
strings in c language and its importance
String in c
Character Array and String
String C Programming

What's hot (20)

PPTX
Strings in C
PPT
Strings
PPT
Strings Functions in C Programming
PPT
Strings
PPT
Strings in c
PPT
PDF
Strinng Classes in c++
PDF
String.ppt
PPT
Operation on string presentation
PPTX
Handling of character strings C programming
PPTX
Array and string
PDF
PDF
05 c++-strings
PDF
Arrays and strings in c++
PPTX
function, storage class and array and strings
PPTX
C programming - String
PPTX
C++ string
PPTX
Implementation Of String Functions In C
Strings in C
Strings
Strings Functions in C Programming
Strings
Strings in c
Strinng Classes in c++
String.ppt
Operation on string presentation
Handling of character strings C programming
Array and string
05 c++-strings
Arrays and strings in c++
function, storage class and array and strings
C programming - String
C++ string
Implementation Of String Functions In C
Ad

Similar to Strings in programming tutorial. (20)

PDF
strings-150319180934-conversion-gate01.pdf
PPTX
Programming in C - Fundamental Study of Strings
PDF
[ITP - Lecture 17] Strings in C/C++
PDF
Strings-Computer programming
PDF
STRINGS IN C MRS.SOWMYA JYOTHI.pdf
PDF
Strings in c mrs.sowmya jyothi
PPTX
fundamentals of c programming_String.pptx
PPTX
Strings CPU GTU
PPTX
String_Slide.pptxStructure.pptxStructure.pptxStructure.pptxStructure.pptx
PDF
0-Slot21-22-Strings.pdf
PPTX
COm1407: Character & Strings
PPT
Lecture 17 - Strings
PPT
PDF
5 2. string processing
PPT
Unit-3 Strings.pptreeeeeeeeeeeeeereeeeere
PPT
Cfbcgdhfghdfhghggfhghghgfhgfhgfhhapter11.PPT
PPT
Chapterabcdefghijklmnopqrdstuvwxydanniipo
PPT
String & its application
PPT
THE FORMAT AND USAGE OF STRINGS IN C.PPT
strings-150319180934-conversion-gate01.pdf
Programming in C - Fundamental Study of Strings
[ITP - Lecture 17] Strings in C/C++
Strings-Computer programming
STRINGS IN C MRS.SOWMYA JYOTHI.pdf
Strings in c mrs.sowmya jyothi
fundamentals of c programming_String.pptx
Strings CPU GTU
String_Slide.pptxStructure.pptxStructure.pptxStructure.pptxStructure.pptx
0-Slot21-22-Strings.pdf
COm1407: Character & Strings
Lecture 17 - Strings
5 2. string processing
Unit-3 Strings.pptreeeeeeeeeeeeeereeeeere
Cfbcgdhfghdfhghggfhghghgfhgfhgfhhapter11.PPT
Chapterabcdefghijklmnopqrdstuvwxydanniipo
String & its application
THE FORMAT AND USAGE OF STRINGS IN C.PPT
Ad

More from Samsil Arefin (20)

PPTX
Transmission Control Protocol and User Datagram protocol
PDF
Evolution Phylogenetic
PPTX
Evolution Phylogenetic
PDF
Ego net facebook data analysis
PPTX
Augmented Reality (AR)
PPTX
Client server chat application
PDF
Linked list searching deleting inserting
PPTX
Number theory
PDF
Program to sort the n names in an alphabetical order
PDF
Linked list int_data_fdata
PDF
Linked list Output tracing
PDF
PPT
Sorting
PPTX
Fundamentals of-electric-circuit
PPTX
Cyber security
PDF
C programming
PPTX
Data structure lecture 1
PPT
Structure and union
PPT
Structure in programming in c or c++ or c# or java
PPTX
Transmission Control Protocol and User Datagram protocol
Evolution Phylogenetic
Evolution Phylogenetic
Ego net facebook data analysis
Augmented Reality (AR)
Client server chat application
Linked list searching deleting inserting
Number theory
Program to sort the n names in an alphabetical order
Linked list int_data_fdata
Linked list Output tracing
Sorting
Fundamentals of-electric-circuit
Cyber security
C programming
Data structure lecture 1
Structure and union
Structure in programming in c or c++ or c# or java

Recently uploaded (20)

PDF
Mohammad Mahdi Farshadian CV - Prospective PhD Student 2026
PPTX
Recipes for Real Time Voice AI WebRTC, SLMs and Open Source Software.pptx
PDF
keyrequirementskkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkk
PPTX
MET 305 2019 SCHEME MODULE 2 COMPLETE.pptx
PPTX
CARTOGRAPHY AND GEOINFORMATION VISUALIZATION chapter1 NPTE (2).pptx
PPTX
Welding lecture in detail for understanding
PPT
Mechanical Engineering MATERIALS Selection
PDF
Mitigating Risks through Effective Management for Enhancing Organizational Pe...
PPTX
Internet of Things (IOT) - A guide to understanding
PDF
PRIZ Academy - 9 Windows Thinking Where to Invest Today to Win Tomorrow.pdf
PPTX
Engineering Ethics, Safety and Environment [Autosaved] (1).pptx
PDF
composite construction of structures.pdf
PPTX
bas. eng. economics group 4 presentation 1.pptx
PPTX
Geodesy 1.pptx...............................................
PPTX
Strings in CPP - Strings in C++ are sequences of characters used to store and...
PPT
Project quality management in manufacturing
PDF
BMEC211 - INTRODUCTION TO MECHATRONICS-1.pdf
DOCX
ASol_English-Language-Literature-Set-1-27-02-2023-converted.docx
DOCX
573137875-Attendance-Management-System-original
PDF
Digital Logic Computer Design lecture notes
Mohammad Mahdi Farshadian CV - Prospective PhD Student 2026
Recipes for Real Time Voice AI WebRTC, SLMs and Open Source Software.pptx
keyrequirementskkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkk
MET 305 2019 SCHEME MODULE 2 COMPLETE.pptx
CARTOGRAPHY AND GEOINFORMATION VISUALIZATION chapter1 NPTE (2).pptx
Welding lecture in detail for understanding
Mechanical Engineering MATERIALS Selection
Mitigating Risks through Effective Management for Enhancing Organizational Pe...
Internet of Things (IOT) - A guide to understanding
PRIZ Academy - 9 Windows Thinking Where to Invest Today to Win Tomorrow.pdf
Engineering Ethics, Safety and Environment [Autosaved] (1).pptx
composite construction of structures.pdf
bas. eng. economics group 4 presentation 1.pptx
Geodesy 1.pptx...............................................
Strings in CPP - Strings in C++ are sequences of characters used to store and...
Project quality management in manufacturing
BMEC211 - INTRODUCTION TO MECHATRONICS-1.pdf
ASol_English-Language-Literature-Set-1-27-02-2023-converted.docx
573137875-Attendance-Management-System-original
Digital Logic Computer Design lecture notes

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