SlideShare a Scribd company logo
Kinan keshkeh 
IT Engineering-Damascus University 
3rd year 
Summer course- 2014 
2 bytes team
Strings !
Strings 
1.C- String (Array of chars ) 
2.Objects from String Classs
C-Strings !
C-Strings 
•It’s an Array of chars ends with ‘ 0 ’ (NULL character) 
•Syntax : 
char Array_Name[Maximum_C-string_Size + 1];
C-Strings 
•char s[10+=“Hi Mom!”
C-Strings 
•It’s an Array of chars ends with ‘ 0 ’ (NULL character) 
•Syntax : 
char Array_Name[Maximum_C-string_Size + 1]; 
•initialize: 
•char arr*+=“kinan” 
•char arr[10+=“kinan” 
•char aString[10]; aString = "Hello";
C-Strings 
•It’s an Array of chars ends with ‘ 0 ’ (NULL character) 
•Syntax : 
char Array_Name[Maximum_C-string_Size + 1]; 
•initialize: 
•char arr*+=“kinan” 
•char arr[10+=“kinan” 
•char aString[10]; aString = "Hello"; 
An Error , you cant write that !!!
C-Strings 
•char arr[5+=,‘k’,’i’,’n’,’a’,’n’-; 
•char arr[10+=,‘k’,’i’,’n’,’a’,’n’-;
C-Strings 
•char arr[5+=,‘k’,’i’,’n’,’a’,’n’-; 
•char arr[10+=,‘k’,’i’,’n’,’a’,’n’-; 
An Error cause the ‘0’ isn’t added 
•char arr[6+=,‘k’,’i’,’n’,’a’,’n’-; 
This is true !
C-Strings 
1.#include <iostream>; 
2.using namespace std; 
3.int main(){ 
4.char A[]="Pascal", B[20]="Ahmad" ; 
5.cout <<"A contains '"<< A<<"'" 
6.<<", its size :"<< sizeof (A) <<endl; 
7.cout <<"B contains '"<< B<<"'" 
8.<<", its size :"<< sizeof (B) <<endl; 
9.} 
A contains 'Pascal', its size :7 
B contains 'Ahmad', its size :20
C-Strings 
1.#include <iostream>; 
2.using namespace std; 
3.int main(){ 
4.char A[]="Pascal", B[20]="Ahmad" ; 
5.cout <<"A contains '"<< A<<"'" 
6.<<", its size :"<< sizeof (A) <<endl; 
7.cout <<"B contains '"<< B<<"'" 
8.<<", its size :"<< sizeof (B) <<endl; 
9.} 
A contains 'Pascal', its size :7 
B contains 'Ahmad', its size :20
C-Strings 
#include <iostream>; using namespace std; int main(){ char ourString[20]="Blaise Pascal" ; int index = 0; while (ourString[index] != '0') { if (ourString[index]==' ') ourString[index]='-'; index++; } cout << ourString; } 
Blaise-Pascal
C-Strings
C-Strings
C-Strings
C-Strings
C-Strings
C-Strings 
•char aString[10]; aString = "Hello"; 
An Error , you cant write that !!! 
•char aString[10]; strcpy(aString ," Hello"); 
But with strcpy u can !!
C-Strings 
#include <iostream> 
#include<cstring> 
using namespace std; 
int main(){ 
char ourString[14]="KINAN" ; 
strcpy(ourString,"keshkeh!!"); 
cout<<ourString<<endl; 
system("pause"); 
return 0 ;} 
keshkeh!!
C-Strings 
#include <iostream> 
#include<cstring> 
using namespace std; 
int main(){ 
char ourString[6]="KINAN" ; 
strcpy(ourString,"keshkehhhhhhhhhhhhhhhhhhhhhhhhhh!!"); 
cout<<ourString<<endl; 
system("pause"); 
return 0 ;} 
keshkehhhhhhhhhhhhhhhhhhhhhhhhhh!! 
compile and run but with warring
C-Strings 
#include <iostream> 
#include<cstring> 
using namespace std; 
int main(){ 
char ourString[20]="Blaise Pascal"; 
if (strcmp(ourString, "Blaise Pascal")) 
cout << "The strings are NOT the same."; 
else 
cout << "The strings are the same."; 
system("pause"); return 0 ;} 
The strings are the same.
C-Strings 
#include <iostream> 
#include<cstring> 
using namespace std; 
int main(){ 
char ourString[20]="Blaise Pascal"; 
cout<<strcmp(ourString, "Blaise Pascal")<<endl; 
system("pause"); return 0 ;} 
0
C-Strings 
The Operation 
Methods 
Input /output 
const int size=10; 
char arr[size]; 
cin>>arr; 
const int max=10; 
char arr[max]; 
cin.getline( arr,max); 
const int max=20; 
char arr[max]; 
cin.get( arr,max,’$’); /* ’$’ when u will end*/ 
cout<<arr; 
cout<<arr; 
cout<<arr; 
ends in Enter+doesn’t take spaces (ex”ki sks” take ”ki” ) 
so you can’t input more than 
Takes the spaces ‘ ‘ ,but doesn’t take Enter if any 
(ex “ ki na n 
keshkeh” , take 
“ki na n“(till Eenter)) 
-Takse Enter + spaces (ex 
“ki n a 
n ke 
shkeh ” take all (till 20 chars)) 
- it can be: cin.get( char);
C-Strings 
cout << "Enter a line of input and I will echo it:n"; char symbol; do { cin.get(symbol); cout << symbol; - while (symbol != ’n’); cout << "That’s all for this demonstration.n"; 
Enter a line of input and I will echo it: 
Do Be Do 1 2 34 
Do Be Do 1 2 34 
That’s all for this demonstration.
Character Manipulation Tools
Character Manipulation Tools
Character Manipulation Tools
Character Manipulation Tools
String !
String 
•It’s a library . 
•Like any type . 
•You can use ‘+’, ‘=’, ‘==’ ,’<=’ .
String
String 
The Operation 
Methods 
Input /output 
String name; 
cin>>name; 
String name; 
getline( cin , name); 
String name; 
getline( cin , name,’$’); 
/* ’$’ when u will end*/ 
cout<<name; 
cout<<name; 
cout<<name; 
ends in Enter+doesn’t take spaces (ex”ki sks” take ”ki” ) 
so you can’t input more than 
Takes the spaces ‘ ‘ ,but doesn’t take Enter if any 
(ex “ ki na n 
keshkeh” , take 
“ki na n“(till Eenter)) 
-Takse Enter + spaces (ex 
“ki n a 
n ke 
shkeh ” take all (till 20 chars))
String 
•You can access the characters in a string object in the same way that you access array elements 
#include<iostream> #include<string> using namespace std; int main( ) { string name="ali"; for (unsigned int i=0;i<name.length();i++) name[i]=toupper(name[i]); //or name.at(i)=toupper(name.at(i)); cout << name << endl; }
String 
•If we have : 
char aCString[] = "This is my C-string."; 
string stringVariable; 
strcpy(aCString, stringVariable); 
aCString = stringVariable; 
aCString = stringVariable.c_str( );
String 
•If we have : 
char aCString[] = "This is my C-string."; string stringVariable; 
strcpy(aCString, stringVariable); 
aCString = stringVariable; 
aCString = stringVariable.c_str( ); 
False !! 
strcpy(stringVariable.c_str( ), aCString); 
True !!
String
String
Code discussion 4
Code discussion 4
Code discussion 4
Code discussion 4
Code discussion 4
That’s for today 
Have a good day ! 
Bye Bye !
2 bytes team 
Group : group link 
Mobile phone- Kinan : 0994385748 
Facebook account : kinan’s account 
2 bytes team

More Related Content

What's hot

Go Containers
Go ContainersGo Containers
Go Containers
jgrahamc
 
Documento de acrobat2
Documento de acrobat2Documento de acrobat2
Documento de acrobat2
fraytuck
 
CBSE Class XII Comp sc practical file
CBSE Class XII Comp sc practical fileCBSE Class XII Comp sc practical file
CBSE Class XII Comp sc practical file
Pranav Ghildiyal
 
Sol7
Sol7Sol7
Swift School #1
Swift School #1Swift School #1
Swift School #1
Sergey Pronin
 
Cpp c++ 1
Cpp c++ 1Cpp c++ 1
Pointer level 2
Pointer   level 2Pointer   level 2
Pointer level 2
Mohammed Sikander
 
The Ring programming language version 1.5.3 book - Part 40 of 184
The Ring programming language version 1.5.3 book - Part 40 of 184The Ring programming language version 1.5.3 book - Part 40 of 184
The Ring programming language version 1.5.3 book - Part 40 of 184
Mahmoud Samir Fayed
 
Array using recursion
Array using recursionArray using recursion
Array using recursion
Swarup Boro
 
programming fundamentals
programming fundamentalsprogramming fundamentals
programming fundamentals
Farhan ullah baig
 
Regular expressions, Alex Perry, Google, PyCon2014
Regular expressions, Alex Perry, Google, PyCon2014Regular expressions, Alex Perry, Google, PyCon2014
Regular expressions, Alex Perry, Google, PyCon2014
alex_perry
 
Sortings
SortingsSortings
Sortings
maamir farooq
 
ECMAScript 5: Новое в JavaScript
ECMAScript 5: Новое в JavaScriptECMAScript 5: Новое в JavaScript
Pointer level 2
Pointer   level 2Pointer   level 2
Pointer level 2
mohamed sikander
 
C- Programs - Harsh
C- Programs - HarshC- Programs - Harsh
C- Programs - Harsh
Harsh Sharma
 
Goroutines and Channels in practice
Goroutines and Channels in practiceGoroutines and Channels in practice
Goroutines and Channels in practice
Guilherme Garnier
 
Hybrid Inheritance in C++
Hybrid Inheritance in C++Hybrid Inheritance in C++
Hybrid Inheritance in C++
Abhishek Pratap
 
lldb – Debugger auf Abwegen
lldb – Debugger auf Abwegenlldb – Debugger auf Abwegen
lldb – Debugger auf Abwegen
inovex GmbH
 
A Shiny Example-- R
A Shiny Example-- RA Shiny Example-- R
A Shiny Example-- R
Dr. Volkan OBAN
 
Class array
Class arrayClass array
Class array
nky92
 

What's hot (20)

Go Containers
Go ContainersGo Containers
Go Containers
 
Documento de acrobat2
Documento de acrobat2Documento de acrobat2
Documento de acrobat2
 
CBSE Class XII Comp sc practical file
CBSE Class XII Comp sc practical fileCBSE Class XII Comp sc practical file
CBSE Class XII Comp sc practical file
 
Sol7
Sol7Sol7
Sol7
 
Swift School #1
Swift School #1Swift School #1
Swift School #1
 
Cpp c++ 1
Cpp c++ 1Cpp c++ 1
Cpp c++ 1
 
Pointer level 2
Pointer   level 2Pointer   level 2
Pointer level 2
 
The Ring programming language version 1.5.3 book - Part 40 of 184
The Ring programming language version 1.5.3 book - Part 40 of 184The Ring programming language version 1.5.3 book - Part 40 of 184
The Ring programming language version 1.5.3 book - Part 40 of 184
 
Array using recursion
Array using recursionArray using recursion
Array using recursion
 
programming fundamentals
programming fundamentalsprogramming fundamentals
programming fundamentals
 
Regular expressions, Alex Perry, Google, PyCon2014
Regular expressions, Alex Perry, Google, PyCon2014Regular expressions, Alex Perry, Google, PyCon2014
Regular expressions, Alex Perry, Google, PyCon2014
 
Sortings
SortingsSortings
Sortings
 
ECMAScript 5: Новое в JavaScript
ECMAScript 5: Новое в JavaScriptECMAScript 5: Новое в JavaScript
ECMAScript 5: Новое в JavaScript
 
Pointer level 2
Pointer   level 2Pointer   level 2
Pointer level 2
 
C- Programs - Harsh
C- Programs - HarshC- Programs - Harsh
C- Programs - Harsh
 
Goroutines and Channels in practice
Goroutines and Channels in practiceGoroutines and Channels in practice
Goroutines and Channels in practice
 
Hybrid Inheritance in C++
Hybrid Inheritance in C++Hybrid Inheritance in C++
Hybrid Inheritance in C++
 
lldb – Debugger auf Abwegen
lldb – Debugger auf Abwegenlldb – Debugger auf Abwegen
lldb – Debugger auf Abwegen
 
A Shiny Example-- R
A Shiny Example-- RA Shiny Example-- R
A Shiny Example-- R
 
Class array
Class arrayClass array
Class array
 

Similar to 2 BytesC++ course_2014_c8_ strings

Strings in c++
Strings in c++Strings in c++
Strings in c++
Neeru Mittal
 
COm1407: Character & Strings
COm1407: Character & StringsCOm1407: Character & Strings
COm1407: Character & Strings
Hemantha Kulathilake
 
Array and string in C++_093547 analysis.pptx
Array and string in C++_093547 analysis.pptxArray and string in C++_093547 analysis.pptx
Array and string in C++_093547 analysis.pptx
JumanneChiyanda
 
Arrays & Strings.pptx
Arrays & Strings.pptxArrays & Strings.pptx
Arrays & Strings.pptx
AnkurRajSingh2
 
INDIAN INSTITUTE OF TECHNOLOGY KANPURESC 111M Lec13.pptx
INDIAN INSTITUTE OF TECHNOLOGY KANPURESC 111M Lec13.pptxINDIAN INSTITUTE OF TECHNOLOGY KANPURESC 111M Lec13.pptx
INDIAN INSTITUTE OF TECHNOLOGY KANPURESC 111M Lec13.pptx
AbhimanyuChaure
 
14 strings
14 strings14 strings
14 strings
Rohit Shrivastava
 
String
StringString
String
SANTOSH RATH
 
Presentation more c_programmingcharacter_and_string_handling_
Presentation more c_programmingcharacter_and_string_handling_Presentation more c_programmingcharacter_and_string_handling_
Presentation more c_programmingcharacter_and_string_handling_
KarthicaMarasamy
 
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 in c
String in cString in c
String in c
Suneel Dogra
 
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++
Azeemaj101
 
Lecture 6
Lecture 6Lecture 6
Lecture 6
Mohammed Saleh
 
Java string handling
Java string handlingJava string handling
Java string handling
GaneshKumarKanthiah
 
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
 
Lecture 15_Strings and Dynamic Memory Allocation.pptx
Lecture 15_Strings and  Dynamic Memory Allocation.pptxLecture 15_Strings and  Dynamic Memory Allocation.pptx
Lecture 15_Strings and Dynamic Memory Allocation.pptx
JawadTanvir
 
C++ Strings.ppt
C++ Strings.pptC++ Strings.ppt
C++ Strings.ppt
DilanAlmsa
 
C Programming Strings.docx
C Programming Strings.docxC Programming Strings.docx
C Programming Strings.docx
8759000398
 
fundamentals of c programming_String.pptx
fundamentals of c programming_String.pptxfundamentals of c programming_String.pptx
fundamentals of c programming_String.pptx
JStalinAsstProfessor
 
Data structure week 3
Data structure week 3Data structure week 3
Data structure week 3
karmuhtam
 
lecture5.ppt
lecture5.pptlecture5.ppt
lecture5.ppt
KarthiKeyan462713
 

Similar to 2 BytesC++ course_2014_c8_ strings (20)

Strings in c++
Strings in c++Strings in c++
Strings in c++
 
COm1407: Character & Strings
COm1407: Character & StringsCOm1407: Character & Strings
COm1407: Character & Strings
 
Array and string in C++_093547 analysis.pptx
Array and string in C++_093547 analysis.pptxArray and string in C++_093547 analysis.pptx
Array and string in C++_093547 analysis.pptx
 
Arrays & Strings.pptx
Arrays & Strings.pptxArrays & Strings.pptx
Arrays & Strings.pptx
 
INDIAN INSTITUTE OF TECHNOLOGY KANPURESC 111M Lec13.pptx
INDIAN INSTITUTE OF TECHNOLOGY KANPURESC 111M Lec13.pptxINDIAN INSTITUTE OF TECHNOLOGY KANPURESC 111M Lec13.pptx
INDIAN INSTITUTE OF TECHNOLOGY KANPURESC 111M Lec13.pptx
 
14 strings
14 strings14 strings
14 strings
 
String
StringString
String
 
Presentation more c_programmingcharacter_and_string_handling_
Presentation more c_programmingcharacter_and_string_handling_Presentation more c_programmingcharacter_and_string_handling_
Presentation more c_programmingcharacter_and_string_handling_
 
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
 
String in c
String in cString in c
String 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++
 
Lecture 6
Lecture 6Lecture 6
Lecture 6
 
Java string handling
Java string handlingJava string handling
Java string handling
 
Handling of character strings C programming
Handling of character strings C programmingHandling of character strings C programming
Handling of character strings C programming
 
Lecture 15_Strings and Dynamic Memory Allocation.pptx
Lecture 15_Strings and  Dynamic Memory Allocation.pptxLecture 15_Strings and  Dynamic Memory Allocation.pptx
Lecture 15_Strings and Dynamic Memory Allocation.pptx
 
C++ Strings.ppt
C++ Strings.pptC++ Strings.ppt
C++ Strings.ppt
 
C Programming Strings.docx
C Programming Strings.docxC Programming Strings.docx
C Programming Strings.docx
 
fundamentals of c programming_String.pptx
fundamentals of c programming_String.pptxfundamentals of c programming_String.pptx
fundamentals of c programming_String.pptx
 
Data structure week 3
Data structure week 3Data structure week 3
Data structure week 3
 
lecture5.ppt
lecture5.pptlecture5.ppt
lecture5.ppt
 

More from kinan keshkeh

10 Little Tricks to Get Your Class’s Attention (and Hold It)
10 Little Tricks to Get Your  Class’s Attention (and Hold It)10 Little Tricks to Get Your  Class’s Attention (and Hold It)
10 Little Tricks to Get Your Class’s Attention (and Hold It)
kinan keshkeh
 
Simpson and lagranje dalambair math methods
Simpson and lagranje dalambair math methods Simpson and lagranje dalambair math methods
Simpson and lagranje dalambair math methods
kinan keshkeh
 
Shapes and calculate (area and contour) / C++ oop concept
Shapes and calculate (area and contour) / C++ oop conceptShapes and calculate (area and contour) / C++ oop concept
Shapes and calculate (area and contour) / C++ oop concept
kinan keshkeh
 
Shapes and calculate (area and contour) / C++ oop concept
Shapes and calculate (area and contour) / C++ oop conceptShapes and calculate (area and contour) / C++ oop concept
Shapes and calculate (area and contour) / C++ oop concept
kinan keshkeh
 
GeneticAlgorithms_AND_CuttingWoodAlgorithm
GeneticAlgorithms_AND_CuttingWoodAlgorithm  GeneticAlgorithms_AND_CuttingWoodAlgorithm
GeneticAlgorithms_AND_CuttingWoodAlgorithm
kinan keshkeh
 
Algorithm in discovering and correcting words errors in a dictionary or any w...
Algorithm in discovering and correcting words errors in a dictionary or any w...Algorithm in discovering and correcting words errors in a dictionary or any w...
Algorithm in discovering and correcting words errors in a dictionary or any w...
kinan keshkeh
 
2Bytesprog2 course_2014_c9_graph
2Bytesprog2 course_2014_c9_graph2Bytesprog2 course_2014_c9_graph
2Bytesprog2 course_2014_c9_graph
kinan keshkeh
 
2Bytesprog2 course_2014_c8_units
2Bytesprog2 course_2014_c8_units2Bytesprog2 course_2014_c8_units
2Bytesprog2 course_2014_c8_units
kinan keshkeh
 
2Bytesprog2 course_2014_c7_double_lists
2Bytesprog2 course_2014_c7_double_lists2Bytesprog2 course_2014_c7_double_lists
2Bytesprog2 course_2014_c7_double_lists
kinan keshkeh
 
2Bytesprog2 course_2014_c6_single linked list
2Bytesprog2 course_2014_c6_single linked list2Bytesprog2 course_2014_c6_single linked list
2Bytesprog2 course_2014_c6_single linked list
kinan keshkeh
 
2Bytesprog2 course_2014_c5_pointers
2Bytesprog2 course_2014_c5_pointers2Bytesprog2 course_2014_c5_pointers
2Bytesprog2 course_2014_c5_pointers
kinan keshkeh
 
2Bytesprog2 course_2014_c4_binaryfiles
2Bytesprog2 course_2014_c4_binaryfiles2Bytesprog2 course_2014_c4_binaryfiles
2Bytesprog2 course_2014_c4_binaryfiles
kinan keshkeh
 
2Bytesprog2 course_2014_c3_txtfiles
2Bytesprog2 course_2014_c3_txtfiles2Bytesprog2 course_2014_c3_txtfiles
2Bytesprog2 course_2014_c3_txtfiles
kinan keshkeh
 
2Bytesprog2 course_2014_c2_records
2Bytesprog2 course_2014_c2_records2Bytesprog2 course_2014_c2_records
2Bytesprog2 course_2014_c2_records
kinan keshkeh
 
2Bytesprog2 course_2014_c1_sets
2Bytesprog2 course_2014_c1_sets2Bytesprog2 course_2014_c1_sets
2Bytesprog2 course_2014_c1_sets
kinan keshkeh
 
2Bytesprog2 course_2014_c1_sets
2Bytesprog2 course_2014_c1_sets2Bytesprog2 course_2014_c1_sets
2Bytesprog2 course_2014_c1_sets
kinan keshkeh
 
2Bytesprog2 course_2014_c1_sets
2Bytesprog2 course_2014_c1_sets2Bytesprog2 course_2014_c1_sets
2Bytesprog2 course_2014_c1_sets
kinan keshkeh
 
2Bytesprog2 course_2014_c1_sets
2Bytesprog2 course_2014_c1_sets2Bytesprog2 course_2014_c1_sets
2Bytesprog2 course_2014_c1_sets
kinan keshkeh
 
2 BytesC++ course_2014_c13_ templates
2 BytesC++ course_2014_c13_ templates2 BytesC++ course_2014_c13_ templates
2 BytesC++ course_2014_c13_ templates
kinan keshkeh
 
2 BytesC++ course_2014_c12_ polymorphism
2 BytesC++ course_2014_c12_ polymorphism2 BytesC++ course_2014_c12_ polymorphism
2 BytesC++ course_2014_c12_ polymorphism
kinan keshkeh
 

More from kinan keshkeh (20)

10 Little Tricks to Get Your Class’s Attention (and Hold It)
10 Little Tricks to Get Your  Class’s Attention (and Hold It)10 Little Tricks to Get Your  Class’s Attention (and Hold It)
10 Little Tricks to Get Your Class’s Attention (and Hold It)
 
Simpson and lagranje dalambair math methods
Simpson and lagranje dalambair math methods Simpson and lagranje dalambair math methods
Simpson and lagranje dalambair math methods
 
Shapes and calculate (area and contour) / C++ oop concept
Shapes and calculate (area and contour) / C++ oop conceptShapes and calculate (area and contour) / C++ oop concept
Shapes and calculate (area and contour) / C++ oop concept
 
Shapes and calculate (area and contour) / C++ oop concept
Shapes and calculate (area and contour) / C++ oop conceptShapes and calculate (area and contour) / C++ oop concept
Shapes and calculate (area and contour) / C++ oop concept
 
GeneticAlgorithms_AND_CuttingWoodAlgorithm
GeneticAlgorithms_AND_CuttingWoodAlgorithm  GeneticAlgorithms_AND_CuttingWoodAlgorithm
GeneticAlgorithms_AND_CuttingWoodAlgorithm
 
Algorithm in discovering and correcting words errors in a dictionary or any w...
Algorithm in discovering and correcting words errors in a dictionary or any w...Algorithm in discovering and correcting words errors in a dictionary or any w...
Algorithm in discovering and correcting words errors in a dictionary or any w...
 
2Bytesprog2 course_2014_c9_graph
2Bytesprog2 course_2014_c9_graph2Bytesprog2 course_2014_c9_graph
2Bytesprog2 course_2014_c9_graph
 
2Bytesprog2 course_2014_c8_units
2Bytesprog2 course_2014_c8_units2Bytesprog2 course_2014_c8_units
2Bytesprog2 course_2014_c8_units
 
2Bytesprog2 course_2014_c7_double_lists
2Bytesprog2 course_2014_c7_double_lists2Bytesprog2 course_2014_c7_double_lists
2Bytesprog2 course_2014_c7_double_lists
 
2Bytesprog2 course_2014_c6_single linked list
2Bytesprog2 course_2014_c6_single linked list2Bytesprog2 course_2014_c6_single linked list
2Bytesprog2 course_2014_c6_single linked list
 
2Bytesprog2 course_2014_c5_pointers
2Bytesprog2 course_2014_c5_pointers2Bytesprog2 course_2014_c5_pointers
2Bytesprog2 course_2014_c5_pointers
 
2Bytesprog2 course_2014_c4_binaryfiles
2Bytesprog2 course_2014_c4_binaryfiles2Bytesprog2 course_2014_c4_binaryfiles
2Bytesprog2 course_2014_c4_binaryfiles
 
2Bytesprog2 course_2014_c3_txtfiles
2Bytesprog2 course_2014_c3_txtfiles2Bytesprog2 course_2014_c3_txtfiles
2Bytesprog2 course_2014_c3_txtfiles
 
2Bytesprog2 course_2014_c2_records
2Bytesprog2 course_2014_c2_records2Bytesprog2 course_2014_c2_records
2Bytesprog2 course_2014_c2_records
 
2Bytesprog2 course_2014_c1_sets
2Bytesprog2 course_2014_c1_sets2Bytesprog2 course_2014_c1_sets
2Bytesprog2 course_2014_c1_sets
 
2Bytesprog2 course_2014_c1_sets
2Bytesprog2 course_2014_c1_sets2Bytesprog2 course_2014_c1_sets
2Bytesprog2 course_2014_c1_sets
 
2Bytesprog2 course_2014_c1_sets
2Bytesprog2 course_2014_c1_sets2Bytesprog2 course_2014_c1_sets
2Bytesprog2 course_2014_c1_sets
 
2Bytesprog2 course_2014_c1_sets
2Bytesprog2 course_2014_c1_sets2Bytesprog2 course_2014_c1_sets
2Bytesprog2 course_2014_c1_sets
 
2 BytesC++ course_2014_c13_ templates
2 BytesC++ course_2014_c13_ templates2 BytesC++ course_2014_c13_ templates
2 BytesC++ course_2014_c13_ templates
 
2 BytesC++ course_2014_c12_ polymorphism
2 BytesC++ course_2014_c12_ polymorphism2 BytesC++ course_2014_c12_ polymorphism
2 BytesC++ course_2014_c12_ polymorphism
 

Recently uploaded

UI5con 2024 - Boost Your Development Experience with UI5 Tooling Extensions
UI5con 2024 - Boost Your Development Experience with UI5 Tooling ExtensionsUI5con 2024 - Boost Your Development Experience with UI5 Tooling Extensions
UI5con 2024 - Boost Your Development Experience with UI5 Tooling Extensions
Peter Muessig
 
GreenCode-A-VSCode-Plugin--Dario-Jurisic
GreenCode-A-VSCode-Plugin--Dario-JurisicGreenCode-A-VSCode-Plugin--Dario-Jurisic
GreenCode-A-VSCode-Plugin--Dario-Jurisic
Green Software Development
 
All you need to know about Spring Boot and GraalVM
All you need to know about Spring Boot and GraalVMAll you need to know about Spring Boot and GraalVM
All you need to know about Spring Boot and GraalVM
Alina Yurenko
 
Energy consumption of Database Management - Florina Jonuzi
Energy consumption of Database Management - Florina JonuziEnergy consumption of Database Management - Florina Jonuzi
Energy consumption of Database Management - Florina Jonuzi
Green Software Development
 
Baha Majid WCA4Z IBM Z Customer Council Boston June 2024.pdf
Baha Majid WCA4Z IBM Z Customer Council Boston June 2024.pdfBaha Majid WCA4Z IBM Z Customer Council Boston June 2024.pdf
Baha Majid WCA4Z IBM Z Customer Council Boston June 2024.pdf
Baha Majid
 
UI5con 2024 - Bring Your Own Design System
UI5con 2024 - Bring Your Own Design SystemUI5con 2024 - Bring Your Own Design System
UI5con 2024 - Bring Your Own Design System
Peter Muessig
 
Measures in SQL (SIGMOD 2024, Santiago, Chile)
Measures in SQL (SIGMOD 2024, Santiago, Chile)Measures in SQL (SIGMOD 2024, Santiago, Chile)
Measures in SQL (SIGMOD 2024, Santiago, Chile)
Julian Hyde
 
A Comprehensive Guide on Implementing Real-World Mobile Testing Strategies fo...
A Comprehensive Guide on Implementing Real-World Mobile Testing Strategies fo...A Comprehensive Guide on Implementing Real-World Mobile Testing Strategies fo...
A Comprehensive Guide on Implementing Real-World Mobile Testing Strategies fo...
kalichargn70th171
 
J-Spring 2024 - Going serverless with Quarkus, GraalVM native images and AWS ...
J-Spring 2024 - Going serverless with Quarkus, GraalVM native images and AWS ...J-Spring 2024 - Going serverless with Quarkus, GraalVM native images and AWS ...
J-Spring 2024 - Going serverless with Quarkus, GraalVM native images and AWS ...
Bert Jan Schrijver
 
如何办理(hull学位证书)英国赫尔大学毕业证硕士文凭原版一模一样
如何办理(hull学位证书)英国赫尔大学毕业证硕士文凭原版一模一样如何办理(hull学位证书)英国赫尔大学毕业证硕士文凭原版一模一样
如何办理(hull学位证书)英国赫尔大学毕业证硕士文凭原版一模一样
gapen1
 
Using Query Store in Azure PostgreSQL to Understand Query Performance
Using Query Store in Azure PostgreSQL to Understand Query PerformanceUsing Query Store in Azure PostgreSQL to Understand Query Performance
Using Query Store in Azure PostgreSQL to Understand Query Performance
Grant Fritchey
 
Unlock the Secrets to Effortless Video Creation with Invideo: Your Ultimate G...
Unlock the Secrets to Effortless Video Creation with Invideo: Your Ultimate G...Unlock the Secrets to Effortless Video Creation with Invideo: Your Ultimate G...
Unlock the Secrets to Effortless Video Creation with Invideo: Your Ultimate G...
The Third Creative Media
 
Enums On Steroids - let's look at sealed classes !
Enums On Steroids - let's look at sealed classes !Enums On Steroids - let's look at sealed classes !
Enums On Steroids - let's look at sealed classes !
Marcin Chrost
 
E-Invoicing Implementation: A Step-by-Step Guide for Saudi Arabian Companies
E-Invoicing Implementation: A Step-by-Step Guide for Saudi Arabian CompaniesE-Invoicing Implementation: A Step-by-Step Guide for Saudi Arabian Companies
E-Invoicing Implementation: A Step-by-Step Guide for Saudi Arabian Companies
Quickdice ERP
 
ppt on the brain chip neuralink.pptx
ppt  on   the brain  chip neuralink.pptxppt  on   the brain  chip neuralink.pptx
ppt on the brain chip neuralink.pptx
Reetu63
 
Enhanced Screen Flows UI/UX using SLDS with Tom Kitt
Enhanced Screen Flows UI/UX using SLDS with Tom KittEnhanced Screen Flows UI/UX using SLDS with Tom Kitt
Enhanced Screen Flows UI/UX using SLDS with Tom Kitt
Peter Caitens
 
The Key to Digital Success_ A Comprehensive Guide to Continuous Testing Integ...
The Key to Digital Success_ A Comprehensive Guide to Continuous Testing Integ...The Key to Digital Success_ A Comprehensive Guide to Continuous Testing Integ...
The Key to Digital Success_ A Comprehensive Guide to Continuous Testing Integ...
kalichargn70th171
 
Oracle Database 19c New Features for DBAs and Developers.pptx
Oracle Database 19c New Features for DBAs and Developers.pptxOracle Database 19c New Features for DBAs and Developers.pptx
Oracle Database 19c New Features for DBAs and Developers.pptx
Remote DBA Services
 
What’s New in Odoo 17 – A Complete Roadmap
What’s New in Odoo 17 – A Complete RoadmapWhat’s New in Odoo 17 – A Complete Roadmap
What’s New in Odoo 17 – A Complete Roadmap
Envertis Software Solutions
 
DECODING JAVA THREAD DUMPS: MASTER THE ART OF ANALYSIS
DECODING JAVA THREAD DUMPS: MASTER THE ART OF ANALYSISDECODING JAVA THREAD DUMPS: MASTER THE ART OF ANALYSIS
DECODING JAVA THREAD DUMPS: MASTER THE ART OF ANALYSIS
Tier1 app
 

Recently uploaded (20)

UI5con 2024 - Boost Your Development Experience with UI5 Tooling Extensions
UI5con 2024 - Boost Your Development Experience with UI5 Tooling ExtensionsUI5con 2024 - Boost Your Development Experience with UI5 Tooling Extensions
UI5con 2024 - Boost Your Development Experience with UI5 Tooling Extensions
 
GreenCode-A-VSCode-Plugin--Dario-Jurisic
GreenCode-A-VSCode-Plugin--Dario-JurisicGreenCode-A-VSCode-Plugin--Dario-Jurisic
GreenCode-A-VSCode-Plugin--Dario-Jurisic
 
All you need to know about Spring Boot and GraalVM
All you need to know about Spring Boot and GraalVMAll you need to know about Spring Boot and GraalVM
All you need to know about Spring Boot and GraalVM
 
Energy consumption of Database Management - Florina Jonuzi
Energy consumption of Database Management - Florina JonuziEnergy consumption of Database Management - Florina Jonuzi
Energy consumption of Database Management - Florina Jonuzi
 
Baha Majid WCA4Z IBM Z Customer Council Boston June 2024.pdf
Baha Majid WCA4Z IBM Z Customer Council Boston June 2024.pdfBaha Majid WCA4Z IBM Z Customer Council Boston June 2024.pdf
Baha Majid WCA4Z IBM Z Customer Council Boston June 2024.pdf
 
UI5con 2024 - Bring Your Own Design System
UI5con 2024 - Bring Your Own Design SystemUI5con 2024 - Bring Your Own Design System
UI5con 2024 - Bring Your Own Design System
 
Measures in SQL (SIGMOD 2024, Santiago, Chile)
Measures in SQL (SIGMOD 2024, Santiago, Chile)Measures in SQL (SIGMOD 2024, Santiago, Chile)
Measures in SQL (SIGMOD 2024, Santiago, Chile)
 
A Comprehensive Guide on Implementing Real-World Mobile Testing Strategies fo...
A Comprehensive Guide on Implementing Real-World Mobile Testing Strategies fo...A Comprehensive Guide on Implementing Real-World Mobile Testing Strategies fo...
A Comprehensive Guide on Implementing Real-World Mobile Testing Strategies fo...
 
J-Spring 2024 - Going serverless with Quarkus, GraalVM native images and AWS ...
J-Spring 2024 - Going serverless with Quarkus, GraalVM native images and AWS ...J-Spring 2024 - Going serverless with Quarkus, GraalVM native images and AWS ...
J-Spring 2024 - Going serverless with Quarkus, GraalVM native images and AWS ...
 
如何办理(hull学位证书)英国赫尔大学毕业证硕士文凭原版一模一样
如何办理(hull学位证书)英国赫尔大学毕业证硕士文凭原版一模一样如何办理(hull学位证书)英国赫尔大学毕业证硕士文凭原版一模一样
如何办理(hull学位证书)英国赫尔大学毕业证硕士文凭原版一模一样
 
Using Query Store in Azure PostgreSQL to Understand Query Performance
Using Query Store in Azure PostgreSQL to Understand Query PerformanceUsing Query Store in Azure PostgreSQL to Understand Query Performance
Using Query Store in Azure PostgreSQL to Understand Query Performance
 
Unlock the Secrets to Effortless Video Creation with Invideo: Your Ultimate G...
Unlock the Secrets to Effortless Video Creation with Invideo: Your Ultimate G...Unlock the Secrets to Effortless Video Creation with Invideo: Your Ultimate G...
Unlock the Secrets to Effortless Video Creation with Invideo: Your Ultimate G...
 
Enums On Steroids - let's look at sealed classes !
Enums On Steroids - let's look at sealed classes !Enums On Steroids - let's look at sealed classes !
Enums On Steroids - let's look at sealed classes !
 
E-Invoicing Implementation: A Step-by-Step Guide for Saudi Arabian Companies
E-Invoicing Implementation: A Step-by-Step Guide for Saudi Arabian CompaniesE-Invoicing Implementation: A Step-by-Step Guide for Saudi Arabian Companies
E-Invoicing Implementation: A Step-by-Step Guide for Saudi Arabian Companies
 
ppt on the brain chip neuralink.pptx
ppt  on   the brain  chip neuralink.pptxppt  on   the brain  chip neuralink.pptx
ppt on the brain chip neuralink.pptx
 
Enhanced Screen Flows UI/UX using SLDS with Tom Kitt
Enhanced Screen Flows UI/UX using SLDS with Tom KittEnhanced Screen Flows UI/UX using SLDS with Tom Kitt
Enhanced Screen Flows UI/UX using SLDS with Tom Kitt
 
The Key to Digital Success_ A Comprehensive Guide to Continuous Testing Integ...
The Key to Digital Success_ A Comprehensive Guide to Continuous Testing Integ...The Key to Digital Success_ A Comprehensive Guide to Continuous Testing Integ...
The Key to Digital Success_ A Comprehensive Guide to Continuous Testing Integ...
 
Oracle Database 19c New Features for DBAs and Developers.pptx
Oracle Database 19c New Features for DBAs and Developers.pptxOracle Database 19c New Features for DBAs and Developers.pptx
Oracle Database 19c New Features for DBAs and Developers.pptx
 
What’s New in Odoo 17 – A Complete Roadmap
What’s New in Odoo 17 – A Complete RoadmapWhat’s New in Odoo 17 – A Complete Roadmap
What’s New in Odoo 17 – A Complete Roadmap
 
DECODING JAVA THREAD DUMPS: MASTER THE ART OF ANALYSIS
DECODING JAVA THREAD DUMPS: MASTER THE ART OF ANALYSISDECODING JAVA THREAD DUMPS: MASTER THE ART OF ANALYSIS
DECODING JAVA THREAD DUMPS: MASTER THE ART OF ANALYSIS
 

2 BytesC++ course_2014_c8_ strings

  • 1. Kinan keshkeh IT Engineering-Damascus University 3rd year Summer course- 2014 2 bytes team
  • 3. Strings 1.C- String (Array of chars ) 2.Objects from String Classs
  • 5. C-Strings •It’s an Array of chars ends with ‘ 0 ’ (NULL character) •Syntax : char Array_Name[Maximum_C-string_Size + 1];
  • 7. C-Strings •It’s an Array of chars ends with ‘ 0 ’ (NULL character) •Syntax : char Array_Name[Maximum_C-string_Size + 1]; •initialize: •char arr*+=“kinan” •char arr[10+=“kinan” •char aString[10]; aString = "Hello";
  • 8. C-Strings •It’s an Array of chars ends with ‘ 0 ’ (NULL character) •Syntax : char Array_Name[Maximum_C-string_Size + 1]; •initialize: •char arr*+=“kinan” •char arr[10+=“kinan” •char aString[10]; aString = "Hello"; An Error , you cant write that !!!
  • 9. C-Strings •char arr[5+=,‘k’,’i’,’n’,’a’,’n’-; •char arr[10+=,‘k’,’i’,’n’,’a’,’n’-;
  • 10. C-Strings •char arr[5+=,‘k’,’i’,’n’,’a’,’n’-; •char arr[10+=,‘k’,’i’,’n’,’a’,’n’-; An Error cause the ‘0’ isn’t added •char arr[6+=,‘k’,’i’,’n’,’a’,’n’-; This is true !
  • 11. C-Strings 1.#include <iostream>; 2.using namespace std; 3.int main(){ 4.char A[]="Pascal", B[20]="Ahmad" ; 5.cout <<"A contains '"<< A<<"'" 6.<<", its size :"<< sizeof (A) <<endl; 7.cout <<"B contains '"<< B<<"'" 8.<<", its size :"<< sizeof (B) <<endl; 9.} A contains 'Pascal', its size :7 B contains 'Ahmad', its size :20
  • 12. C-Strings 1.#include <iostream>; 2.using namespace std; 3.int main(){ 4.char A[]="Pascal", B[20]="Ahmad" ; 5.cout <<"A contains '"<< A<<"'" 6.<<", its size :"<< sizeof (A) <<endl; 7.cout <<"B contains '"<< B<<"'" 8.<<", its size :"<< sizeof (B) <<endl; 9.} A contains 'Pascal', its size :7 B contains 'Ahmad', its size :20
  • 13. C-Strings #include <iostream>; using namespace std; int main(){ char ourString[20]="Blaise Pascal" ; int index = 0; while (ourString[index] != '0') { if (ourString[index]==' ') ourString[index]='-'; index++; } cout << ourString; } Blaise-Pascal
  • 19. C-Strings •char aString[10]; aString = "Hello"; An Error , you cant write that !!! •char aString[10]; strcpy(aString ," Hello"); But with strcpy u can !!
  • 20. C-Strings #include <iostream> #include<cstring> using namespace std; int main(){ char ourString[14]="KINAN" ; strcpy(ourString,"keshkeh!!"); cout<<ourString<<endl; system("pause"); return 0 ;} keshkeh!!
  • 21. C-Strings #include <iostream> #include<cstring> using namespace std; int main(){ char ourString[6]="KINAN" ; strcpy(ourString,"keshkehhhhhhhhhhhhhhhhhhhhhhhhhh!!"); cout<<ourString<<endl; system("pause"); return 0 ;} keshkehhhhhhhhhhhhhhhhhhhhhhhhhh!! compile and run but with warring
  • 22. C-Strings #include <iostream> #include<cstring> using namespace std; int main(){ char ourString[20]="Blaise Pascal"; if (strcmp(ourString, "Blaise Pascal")) cout << "The strings are NOT the same."; else cout << "The strings are the same."; system("pause"); return 0 ;} The strings are the same.
  • 23. C-Strings #include <iostream> #include<cstring> using namespace std; int main(){ char ourString[20]="Blaise Pascal"; cout<<strcmp(ourString, "Blaise Pascal")<<endl; system("pause"); return 0 ;} 0
  • 24. C-Strings The Operation Methods Input /output const int size=10; char arr[size]; cin>>arr; const int max=10; char arr[max]; cin.getline( arr,max); const int max=20; char arr[max]; cin.get( arr,max,’$’); /* ’$’ when u will end*/ cout<<arr; cout<<arr; cout<<arr; ends in Enter+doesn’t take spaces (ex”ki sks” take ”ki” ) so you can’t input more than Takes the spaces ‘ ‘ ,but doesn’t take Enter if any (ex “ ki na n keshkeh” , take “ki na n“(till Eenter)) -Takse Enter + spaces (ex “ki n a n ke shkeh ” take all (till 20 chars)) - it can be: cin.get( char);
  • 25. C-Strings cout << "Enter a line of input and I will echo it:n"; char symbol; do { cin.get(symbol); cout << symbol; - while (symbol != ’n’); cout << "That’s all for this demonstration.n"; Enter a line of input and I will echo it: Do Be Do 1 2 34 Do Be Do 1 2 34 That’s all for this demonstration.
  • 31. String •It’s a library . •Like any type . •You can use ‘+’, ‘=’, ‘==’ ,’<=’ .
  • 33. String The Operation Methods Input /output String name; cin>>name; String name; getline( cin , name); String name; getline( cin , name,’$’); /* ’$’ when u will end*/ cout<<name; cout<<name; cout<<name; ends in Enter+doesn’t take spaces (ex”ki sks” take ”ki” ) so you can’t input more than Takes the spaces ‘ ‘ ,but doesn’t take Enter if any (ex “ ki na n keshkeh” , take “ki na n“(till Eenter)) -Takse Enter + spaces (ex “ki n a n ke shkeh ” take all (till 20 chars))
  • 34. String •You can access the characters in a string object in the same way that you access array elements #include<iostream> #include<string> using namespace std; int main( ) { string name="ali"; for (unsigned int i=0;i<name.length();i++) name[i]=toupper(name[i]); //or name.at(i)=toupper(name.at(i)); cout << name << endl; }
  • 35. String •If we have : char aCString[] = "This is my C-string."; string stringVariable; strcpy(aCString, stringVariable); aCString = stringVariable; aCString = stringVariable.c_str( );
  • 36. String •If we have : char aCString[] = "This is my C-string."; string stringVariable; strcpy(aCString, stringVariable); aCString = stringVariable; aCString = stringVariable.c_str( ); False !! strcpy(stringVariable.c_str( ), aCString); True !!
  • 44. That’s for today Have a good day ! Bye Bye !
  • 45. 2 bytes team Group : group link Mobile phone- Kinan : 0994385748 Facebook account : kinan’s account 2 bytes team