SlideShare una empresa de Scribd logo
1 de 25
STRINGS

Name :- Mandeep kaur
Class:- n1
Roll no.:- 115322
INTRODUCTION OF STRING
► Incomputer programming, a string is
 traditionally a sequence of characters, either
 as a literal constant or as some kind of
 variable A string is as a data type and is
 often implemented as a byte (or word)
 array that stores a sequence of elements,
 typically charactersusing some
 character encoding
STORING STRING
► Inc++ language,a string is stored in an array
 of characters.It is terminated by the null (‘0’)
 character.because string is stored in an
 array,the name of the aaray, and hence
 string, is a pointer to the beginning of the
 string.For example “hello”
String Operations

►A number of additional operations on strings
 commonly occur in the formal theory .
String Datatype
►A   string datatype is a datatype


                                    modeled
 on the idea of a formal string . Strings are
 such an important and useful datatype that
 they are implemented in nearly never
 programming language .In some language
 they are avalible as primitive types and in
 others as composite types
String Literals
  ►A  string literal ,also known as string
   constant ,is a sequence of characters
enclosed in double quotes.For example:-
            “hello!you are welcome”
                       “”
                      “a”
String Variables
►   A string variable is actually an array of
    characters.
It has two types
3. Declaring string variables
4. Initializing string variables
STRINGS AND ASSIGNMENT
            OPERATOR
► String  is an array of characters , therefore,
  the name of the array is a pointer constant ,
  it is an rvalue, and therefore cannot be used
  as the left operand of the assignment
  operator.
► For example :- char strl[]= “hello”;
  char str2[20];
  str2=str1;
String lenght
► Although  formal strings can have an arbitrary
 length, the length of strings in real languages is
 often constrained to an artifical maximaum . In
 general, there are two types of string data type .
 Fixed length strings , which have a fixed maximun
 length and which use the same amount of memory
 .whether this maximum is reached or not , and
 variable length strings,whose length is not
 arbitrarity fixed and which use varyingamounts of
 memory depending on their actul size
Character string functions
► Stringfunction are used to manipulate a
 string or change or edit the contents of a
 string. They also are used to query
 information about a string.they are usully
 used within the content of a computer
 programming language
Input/Output of String Data
There are approaches to perform input/output
   of string data.these are two types:-
   using character I/O functions
    using string I/O functions
    The input/output of string data can be
   performed using character I/O functions as
   illustrated in the following programs .
Program to perform input/output of string data with
character I/O functions of streams objects cin &cout
►   #include<iostream.h>
►   Void main()
►   {
►   Char str[30];
►   Int I,n=0;
►   Cout<<“n enter string of length <=29”;
►   Cout<<“n and terminate with ENTER keynn”;
►   While( (str[n]=cin.get() )!=‘n’)
►   N++;
►   Str[n]=‘0’
►   Cout<<“n you have entered nn”;
►   For(i=0;i<n;i++)
►   Cout.put(str[i]);
►   Cout<<“n”;
►   }
Progarm to perform input/output of string data with
      getline()function of cin stream object

► #include<iostream.h>void   main
►{
► Char str[30];
► Cout<<“n enter string of length<=29;
► Cout<<“n and terminate with ENTER keynn”;
► Cin.getline(str,30);
► Cout<<“n you have entered nn”;
► Cout<<str;
► Cout<<“n”;
►}
The strlen() function:-This function
 takes one argumentthat can be a string constant or
 a variable. The counts the no. of character present
in the string. Do remember that null character ‘0’ is
not a part of the character, it is merely used to mark
      the end of the string,so it is not counted
The strcat() function
► This  function takes two arguments, of which
 first is a variable and second can be a string
 constant or a variable. It appends the
 character(s) of the second arguments at the
 end of the first argument. There must be
 sufficient avaible to accommodate the
 incoming character from destination
 string,otherwise over flow occurs.
Program to illustrate the useof
                strcat()function
►   #include<iostream.h>
►   #include<string.h>
►   Void main()
►   {
►   Char str[30]=“wel”, str2[30]=“come”;
►   Cout<<“n first string is “<<str1;
►   Cout<<“nn second string after appending second one is
    nn”;
►   Cout<<str<<“n”;
►   }
The strcpy() function
► Thisfunctions takes two arguments, of
 which first is a string variable and second
 can be a string constant or a variable. It
 copies the characters of the second
 argument to the first argument.
The strcmp() function

► This functions takes two arguments, of
  which boyh can be string variables or
  constants.It compares the characters of
  each but one at a time and returns a value
  indicating the result of the comparison.
► For example:-strcmp(str1,str2);
Passing string to a function
►A string can be passed as an argument to a
 function using subscripted notation for
 arrays.In a function definition, the formal
 parameter is delared as an array of
 cahracters.
Program to illustrate the passing of a string to
                   a function
►   #include<iostream.h>
►   #include<string.h>
►   Void func(char[]); //function prototype
►   Void main()
►   {
►   Char str1[]=“sample string’;
►   Func(str1);
►   }
►   Void func(char temp[])
►   {
►   Cout<<“n string passed to it:”<< temp;
►   Cout<<“nn its length is:”<<strlen(temp)<<“n”;
►   }
Array of string
► In two-dimensional arrays,the first row
  stores the first string, the second row stores
  the second string.
► For example:-char names[4] [12];
Safe operations
► As we discuss before, string functions are
 not safe in general since the size of the
 string is not controlled(everything depend
 upon the occurance of the null character)
Safe operations

►A  solution is used in the safer functions:
► Strcmp(), strcat(), strcpy()
► strcmp(dest ,src,n): compare at mast n
  character of dest
► Strcat(dest ,src,n): concatenate atmost n
  character of scr to dest
► Strcpy(dest, scr, n):copy at most n
  character of scr to dest
String processing
► Sscanf()   is very similar to scanf(). The only
  difference is that it takes the the input from
  a string rather than the console.
► Sscanf(char*s, const char,* format,……..)
► For eg: char input-str[50];
► Int i; float f; char st[10];
Thanks

Más contenido relacionado

La actualidad más candente (19)

String c
String cString c
String c
 
String in c programming
String in c programmingString in c programming
String in c programming
 
String in c
String in cString in c
String in c
 
String Handling in c++
String Handling in c++String Handling in c++
String Handling in 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++
String in programming language in c or c++
 
Operation on string presentation
Operation on string presentationOperation on string presentation
Operation on string presentation
 
The string class
The string classThe string class
The string class
 
Handling of character strings C programming
Handling of character strings C programmingHandling of character strings C programming
Handling of character strings C programming
 
Strings in c
Strings in cStrings in c
Strings in c
 
Strings
StringsStrings
Strings
 
Strings
StringsStrings
Strings
 
Strings
StringsStrings
Strings
 
Character Array and String
Character Array and StringCharacter Array and String
Character Array and String
 
Strings in programming tutorial.
Strings  in programming tutorial.Strings  in programming tutorial.
Strings in programming tutorial.
 
String functions in C
String functions in CString functions in C
String functions in C
 
Strings IN C
Strings IN CStrings IN C
Strings IN C
 
Strings in c++
Strings in c++Strings in c++
Strings in c++
 
Strings in c++
Strings in c++Strings in c++
Strings in c++
 
Chap 8(strings)
Chap 8(strings)Chap 8(strings)
Chap 8(strings)
 

Destacado

Weihnachtskalender
WeihnachtskalenderWeihnachtskalender
Weihnachtskalenderherrkarl
 
Muguet porte Bonheur 2011
Muguet porte Bonheur 2011Muguet porte Bonheur 2011
Muguet porte Bonheur 2011Charlotte **
 
Round 2|Asian道場2012モーション発表
Round 2|Asian道場2012モーション発表Round 2|Asian道場2012モーション発表
Round 2|Asian道場2012モーション発表asiandojo
 
'Watch Out'
'Watch Out''Watch Out'
'Watch Out'John *
 
Lesseptmerveillesdumonde
LesseptmerveillesdumondeLesseptmerveillesdumonde
Lesseptmerveillesdumondewestberti71
 
Vacation gone wrong
Vacation gone wrongVacation gone wrong
Vacation gone wrongcoolstuff
 
Mes amies les roses charlotte.-
Mes amies les roses   charlotte.-Mes amies les roses   charlotte.-
Mes amies les roses charlotte.-Charlotte **
 
09 Le Meilleur Des Blagues Macho
09 Le Meilleur Des Blagues Macho09 Le Meilleur Des Blagues Macho
09 Le Meilleur Des Blagues Machoguestb00ba9
 
magnifique-hommage-aux-femmes
 magnifique-hommage-aux-femmes magnifique-hommage-aux-femmes
magnifique-hommage-aux-femmesEugenia silva
 
Les Phrases Qui Tuent
Les Phrases Qui TuentLes Phrases Qui Tuent
Les Phrases Qui Tuentguestfea295
 
Novo Blindado Russo
Novo Blindado RussoNovo Blindado Russo
Novo Blindado Russoalex
 
عسل و ارزش دارویی آن --- تهیه کننده : سعید رنجبریان
عسل و ارزش دارویی آن  --- تهیه کننده : سعید رنجبریانعسل و ارزش دارویی آن  --- تهیه کننده : سعید رنجبریان
عسل و ارزش دارویی آن --- تهیه کننده : سعید رنجبریانSaeed Ranjbaryan
 
China 衛國軍魂
China   衛國軍魂China   衛國軍魂
China 衛國軍魂nk1953
 
Piódão
PiódãoPiódão
Piódãoalex
 
Naica Acavernadosgigantes
Naica AcavernadosgigantesNaica Acavernadosgigantes
Naica AcavernadosgigantesRosário Rocha
 
Kurios Fun
Kurios Fun Kurios Fun
Kurios Fun alex
 
Cema 2006
Cema 2006Cema 2006
Cema 2006alex
 

Destacado (20)

1027 presentation
1027 presentation1027 presentation
1027 presentation
 
Weihnachtskalender
WeihnachtskalenderWeihnachtskalender
Weihnachtskalender
 
Muguet porte Bonheur 2011
Muguet porte Bonheur 2011Muguet porte Bonheur 2011
Muguet porte Bonheur 2011
 
Round 2|Asian道場2012モーション発表
Round 2|Asian道場2012モーション発表Round 2|Asian道場2012モーション発表
Round 2|Asian道場2012モーション発表
 
'Watch Out'
'Watch Out''Watch Out'
'Watch Out'
 
Lesseptmerveillesdumonde
LesseptmerveillesdumondeLesseptmerveillesdumonde
Lesseptmerveillesdumonde
 
Vacation gone wrong
Vacation gone wrongVacation gone wrong
Vacation gone wrong
 
Mes amies les roses charlotte.-
Mes amies les roses   charlotte.-Mes amies les roses   charlotte.-
Mes amies les roses charlotte.-
 
ellayel
ellayelellayel
ellayel
 
09 Le Meilleur Des Blagues Macho
09 Le Meilleur Des Blagues Macho09 Le Meilleur Des Blagues Macho
09 Le Meilleur Des Blagues Macho
 
magnifique-hommage-aux-femmes
 magnifique-hommage-aux-femmes magnifique-hommage-aux-femmes
magnifique-hommage-aux-femmes
 
Les Phrases Qui Tuent
Les Phrases Qui TuentLes Phrases Qui Tuent
Les Phrases Qui Tuent
 
Novo Blindado Russo
Novo Blindado RussoNovo Blindado Russo
Novo Blindado Russo
 
01cleopatra
01cleopatra01cleopatra
01cleopatra
 
عسل و ارزش دارویی آن --- تهیه کننده : سعید رنجبریان
عسل و ارزش دارویی آن  --- تهیه کننده : سعید رنجبریانعسل و ارزش دارویی آن  --- تهیه کننده : سعید رنجبریان
عسل و ارزش دارویی آن --- تهیه کننده : سعید رنجبریان
 
China 衛國軍魂
China   衛國軍魂China   衛國軍魂
China 衛國軍魂
 
Piódão
PiódãoPiódão
Piódão
 
Naica Acavernadosgigantes
Naica AcavernadosgigantesNaica Acavernadosgigantes
Naica Acavernadosgigantes
 
Kurios Fun
Kurios Fun Kurios Fun
Kurios Fun
 
Cema 2006
Cema 2006Cema 2006
Cema 2006
 

Similar a Strings (20)

introduction to strings in c programming
introduction to strings in c programmingintroduction to strings in c programming
introduction to strings in c programming
 
Team 1
Team 1Team 1
Team 1
 
C q 3
C q 3C q 3
C q 3
 
Strings part2
Strings part2Strings part2
Strings part2
 
CP-STRING (1).ppt
CP-STRING (1).pptCP-STRING (1).ppt
CP-STRING (1).ppt
 
CP-STRING.ppt
CP-STRING.pptCP-STRING.ppt
CP-STRING.ppt
 
CP-STRING.ppt
CP-STRING.pptCP-STRING.ppt
CP-STRING.ppt
 
String notes
String notesString notes
String notes
 
0-Slot21-22-Strings.pdf
0-Slot21-22-Strings.pdf0-Slot21-22-Strings.pdf
0-Slot21-22-Strings.pdf
 
Unitii string
Unitii stringUnitii string
Unitii string
 
CPSTRINGSARGAVISTRINGS.PPT
CPSTRINGSARGAVISTRINGS.PPTCPSTRINGSARGAVISTRINGS.PPT
CPSTRINGSARGAVISTRINGS.PPT
 
BHARGAVISTRINGS.PPT
BHARGAVISTRINGS.PPTBHARGAVISTRINGS.PPT
BHARGAVISTRINGS.PPT
 
structure,pointerandstring
structure,pointerandstringstructure,pointerandstring
structure,pointerandstring
 
Strings in c mrs.sowmya jyothi
Strings in c mrs.sowmya jyothiStrings in c mrs.sowmya jyothi
Strings in c mrs.sowmya jyothi
 
Strings in Python
Strings in PythonStrings in Python
Strings in Python
 
Strings(2007)
Strings(2007)Strings(2007)
Strings(2007)
 
strings
stringsstrings
strings
 
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
 
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++
 

Último

"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek SchlawackFwdays
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity PlanDatabarracks
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.Curtis Poe
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLScyllaDB
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenHervé Boutemy
 
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxThe Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxLoriGlavin3
 
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxThe Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxLoriGlavin3
 
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxA Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxLoriGlavin3
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsRizwan Syed
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfAddepto
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfAlex Barbosa Coqueiro
 
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024BookNet Canada
 
The State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxThe State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxLoriGlavin3
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupFlorian Wilhelm
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxNavinnSomaal
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxLoriGlavin3
 
Moving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfMoving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfLoriGlavin3
 
unit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptxunit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptxBkGupta21
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Commit University
 

Último (20)

"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity Plan
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQL
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache Maven
 
DMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special EditionDMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special Edition
 
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxThe Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
 
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxThe Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
 
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxA Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL Certs
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdf
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdf
 
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
 
The State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxThe State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptx
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project Setup
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptx
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
 
Moving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfMoving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdf
 
unit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptxunit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptx
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!
 

Strings

  • 1. STRINGS Name :- Mandeep kaur Class:- n1 Roll no.:- 115322
  • 2. INTRODUCTION OF STRING ► Incomputer programming, a string is traditionally a sequence of characters, either as a literal constant or as some kind of variable A string is as a data type and is often implemented as a byte (or word) array that stores a sequence of elements, typically charactersusing some character encoding
  • 3. STORING STRING ► Inc++ language,a string is stored in an array of characters.It is terminated by the null (‘0’) character.because string is stored in an array,the name of the aaray, and hence string, is a pointer to the beginning of the string.For example “hello”
  • 4. String Operations ►A number of additional operations on strings commonly occur in the formal theory .
  • 5. String Datatype ►A string datatype is a datatype modeled on the idea of a formal string . Strings are such an important and useful datatype that they are implemented in nearly never programming language .In some language they are avalible as primitive types and in others as composite types
  • 6. String Literals ►A string literal ,also known as string constant ,is a sequence of characters enclosed in double quotes.For example:- “hello!you are welcome” “” “a”
  • 7. String Variables ► A string variable is actually an array of characters. It has two types 3. Declaring string variables 4. Initializing string variables
  • 8. STRINGS AND ASSIGNMENT OPERATOR ► String is an array of characters , therefore, the name of the array is a pointer constant , it is an rvalue, and therefore cannot be used as the left operand of the assignment operator. ► For example :- char strl[]= “hello”; char str2[20]; str2=str1;
  • 9. String lenght ► Although formal strings can have an arbitrary length, the length of strings in real languages is often constrained to an artifical maximaum . In general, there are two types of string data type . Fixed length strings , which have a fixed maximun length and which use the same amount of memory .whether this maximum is reached or not , and variable length strings,whose length is not arbitrarity fixed and which use varyingamounts of memory depending on their actul size
  • 10. Character string functions ► Stringfunction are used to manipulate a string or change or edit the contents of a string. They also are used to query information about a string.they are usully used within the content of a computer programming language
  • 11. Input/Output of String Data There are approaches to perform input/output of string data.these are two types:- using character I/O functions using string I/O functions The input/output of string data can be performed using character I/O functions as illustrated in the following programs .
  • 12. Program to perform input/output of string data with character I/O functions of streams objects cin &cout ► #include<iostream.h> ► Void main() ► { ► Char str[30]; ► Int I,n=0; ► Cout<<“n enter string of length <=29”; ► Cout<<“n and terminate with ENTER keynn”; ► While( (str[n]=cin.get() )!=‘n’) ► N++; ► Str[n]=‘0’ ► Cout<<“n you have entered nn”; ► For(i=0;i<n;i++) ► Cout.put(str[i]); ► Cout<<“n”; ► }
  • 13. Progarm to perform input/output of string data with getline()function of cin stream object ► #include<iostream.h>void main ►{ ► Char str[30]; ► Cout<<“n enter string of length<=29; ► Cout<<“n and terminate with ENTER keynn”; ► Cin.getline(str,30); ► Cout<<“n you have entered nn”; ► Cout<<str; ► Cout<<“n”; ►}
  • 14. The strlen() function:-This function takes one argumentthat can be a string constant or a variable. The counts the no. of character present in the string. Do remember that null character ‘0’ is not a part of the character, it is merely used to mark the end of the string,so it is not counted
  • 15. The strcat() function ► This function takes two arguments, of which first is a variable and second can be a string constant or a variable. It appends the character(s) of the second arguments at the end of the first argument. There must be sufficient avaible to accommodate the incoming character from destination string,otherwise over flow occurs.
  • 16. Program to illustrate the useof strcat()function ► #include<iostream.h> ► #include<string.h> ► Void main() ► { ► Char str[30]=“wel”, str2[30]=“come”; ► Cout<<“n first string is “<<str1; ► Cout<<“nn second string after appending second one is nn”; ► Cout<<str<<“n”; ► }
  • 17. The strcpy() function ► Thisfunctions takes two arguments, of which first is a string variable and second can be a string constant or a variable. It copies the characters of the second argument to the first argument.
  • 18. The strcmp() function ► This functions takes two arguments, of which boyh can be string variables or constants.It compares the characters of each but one at a time and returns a value indicating the result of the comparison. ► For example:-strcmp(str1,str2);
  • 19. Passing string to a function ►A string can be passed as an argument to a function using subscripted notation for arrays.In a function definition, the formal parameter is delared as an array of cahracters.
  • 20. Program to illustrate the passing of a string to a function ► #include<iostream.h> ► #include<string.h> ► Void func(char[]); //function prototype ► Void main() ► { ► Char str1[]=“sample string’; ► Func(str1); ► } ► Void func(char temp[]) ► { ► Cout<<“n string passed to it:”<< temp; ► Cout<<“nn its length is:”<<strlen(temp)<<“n”; ► }
  • 21. Array of string ► In two-dimensional arrays,the first row stores the first string, the second row stores the second string. ► For example:-char names[4] [12];
  • 22. Safe operations ► As we discuss before, string functions are not safe in general since the size of the string is not controlled(everything depend upon the occurance of the null character)
  • 23. Safe operations ►A solution is used in the safer functions: ► Strcmp(), strcat(), strcpy() ► strcmp(dest ,src,n): compare at mast n character of dest ► Strcat(dest ,src,n): concatenate atmost n character of scr to dest ► Strcpy(dest, scr, n):copy at most n character of scr to dest
  • 24. String processing ► Sscanf() is very similar to scanf(). The only difference is that it takes the the input from a string rather than the console. ► Sscanf(char*s, const char,* format,……..) ► For eg: char input-str[50]; ► Int i; float f; char st[10];