SlideShare ist ein Scribd-Unternehmen logo
1 von 62
Downloaden Sie, um offline zu lesen
Team Emertxe
Strings and Storage
Classes
Assignment 7
Assignment 7
Assignment 7
WAP to implement strtok function
Assignment 7
WAP to implement strtok function
Input:
Assignment 7
WAP to implement strtok function
Input: Read two Strings.
Assignment 7
WAP to implement strtok function
Input: Read two Strings.
Output:
Assignment 7
WAP to implement strtok function
Input: Read two Strings.
Output: Print tokens from string.
Assignment 7
What is strtok() function?
Assignment 7
What is strtok() function?
 The strtok() function breaks a string into a sequence of zero or
more nonempty tokens.
 On the first call to strtok(), the string to be parsed should be
specified in str. In each subsequent call that should parse the
same string, str must be NULL.
Assignment 7
What is strtok() function?
 The strtok() function breaks a string into a sequence of zero or
more nonempty tokens.
 On the first call to strtok(), the string to be parsed should be
specified in str. In each subsequent call that should parse the
same string, str must be NULL.
Prototype: char *strtok(char *str, const char *delim);
Assignment 7
Let’s understand how strtok() works:
Assignment 7
Let’s understand how strtok() works:
Assignment 7
Let’s understand how strtok() works:
What will be printed?
Assignment 7
Let’s understand how strtok() works:
“Are” will be printed
O/p of the program:
Are
Assignment 7
Let’s understand how strtok() works:
What will be printed?
Assignment 7
Let’s understand how strtok() works:
“Are” will be printed
“Are” will be printed
O/p of the program:
Are
Are
Assignment 7
Let’s understand how strtok() works:
But, the next token
should be printed is
“you”
“Are” will be printed
“Are” will be printed
O/p of the program:
Are
Are
Assignment 7
Let’s understand how strtok() works:
What will be printed?
What will be printed?
Assignment 7
Let’s understand how strtok() works:
“you” will be printed
“Are” will be printed
O/p of the program:
Are
you
Assignment 7
Let’s understand how strtok() works:
O/p of the program:
Are
you
How will you print the
remaining tokens?
Assignment 7
Let’s understand how strtok() works:
What is the output?
Assignment 7
Let’s understand how strtok() works:
O/p of the program:
Are
You
okay
Assignment 7
How to implement your own strtok() function?
Assignment 7
How to implement your own strtok() function?
 Input: str = “Are;you:okay”
delim = “;:”
A r e ; y o u : o k a y 0
; : 0
str
delim String containing delimiters,
these delimiters has to be
matched with each and every
character of str
Assignment 7
A r e ; y o u : o k a y 0
; : 0
str
delim
0 1 2 3 4 5 6 7 8 9 10 11 12
start_index
 Input: str = “Are;you:okay”
delim = “;:”
pos
Assignment 7
A r e ; y o u : o k a y 0
; : 0
str
delim
0 1 2 3 4 5 6 7 8 9 10 11 12
start_index
 Input: str = “Are;you:okay”
delim = “;:”
pos
Assignment 7
A r e ; y o u : o k a y 0
; : 0
str
delim
0 1 2 3 4 5 6 7 8 9 10 11 12
start_index
 Input: str = “Are;you:okay”
delim = “;:”
pos
Assignment 7
A r e ; y o u : o k a y 0
; : 0
str
delim
0 1 2 3 4 5 6 7 8 9 10 11 12
start_index
 Input: str = “Are;you:okay”
delim = “;:”
pos
Assignment 7
A r e ; y o u : o k a y 0
; : 0
str
delim
0 1 2 3 4 5 6 7 8 9 10 11 12
start_index
 Input: str = “Are;you:okay”
delim = “;:”
pos
Assignment 7
A r e ; y o u : o k a y 0
; : 0
str
delim
0 1 2 3 4 5 6 7 8 9 10 11 12
start_index
 Input: str = “Are;you:okay”
delim = “;:”
pos
Assignment 7
A r e ; y o u : o k a y 0
; : 0
str
delim
0 1 2 3 4 5 6 7 8 9 10 11 12
start_index
 Input: str = “Are;you:okay”
delim = “;:”
pos Here at pos 3, delimiter is
encountered, so overwrite that
byte with ‘0’
Assignment 7
A r e 0 y o u : o k a y 0
; : 0
str
delim
0 1 2 3 4 5 6 7 8 9 10 11 12
start_index
 Input: str = “Are;you:okay”
delim = “;:”
pos Return the address using str +
start_index and do pos++
Assignment 7
A r e 0 y o u : o k a y 0
; : 0
str
delim
0 1 2 3 4 5 6 7 8 9 10 11 12
start_index
 Input: str = “Are;you:okay”
delim = “;:”
pos Return the address using str +
start_index and do pos++
Output:
Are
Assignment 7
A r e 0 y o u : o k a y 0
; : 0
str
delim
0 1 2 3 4 5 6 7 8 9 10 11 12
start_index
 Input: str = “Are;you:okay”
delim = “;:”
pos
Output:
Are
Assignment 7
A r e 0 y o u : o k a y 0
; : 0
str
delim
0 1 2 3 4 5 6 7 8 9 10 11 12
start_index
 Input: str = “Are;you:okay”
delim = “;:”
pos
Output:
Are
Assignment 7
A r e 0 y o u : o k a y 0
; : 0
str
delim
0 1 2 3 4 5 6 7 8 9 10 11 12
start_index
 Input: str = “Are;you:okay”
delim = “;:”
pos
Output:
Are
Assignment 7
A r e 0 y o u : o k a y 0
; : 0
str
delim
0 1 2 3 4 5 6 7 8 9 10 11 12
start_index
 Input: str = “Are;you:okay”
delim = “;:”
pos
Output:
Are
Assignment 7
A r e 0 y o u : o k a y 0
; : 0
str
delim
0 1 2 3 4 5 6 7 8 9 10 11 12
start_index
 Input: str = “Are;you:okay”
delim = “;:”
pos
Output:
Are
Assignment 7
A r e 0 y o u : o k a y 0
; : 0
str
delim
0 1 2 3 4 5 6 7 8 9 10 11 12
start_index
 Input: str = “Are;you:okay”
delim = “;:”
pos
Output:
Are
Assignment 7
A r e 0 y o u : o k a y 0
; : 0
str
delim
0 1 2 3 4 5 6 7 8 9 10 11 12
start_index
 Input: str = “Are;you:okay”
delim = “;:”
pos
Output:
Are
Assignment 7
A r e 0 y o u : o k a y 0
; : 0
str
delim
0 1 2 3 4 5 6 7 8 9 10 11 12
start_index
 Input: str = “Are;you:okay”
delim = “;:”
pos
Output:
Are
Here at pos 7, delimiter is
encountered, so overwrite that
byte with ‘0’
Assignment 7
A r e 0 y o u 0 o k a y 0
; : 0
str
delim
0 1 2 3 4 5 6 7 8 9 10 11 12
start_index
 Input: str = “Are;you:okay”
delim = “;:”
pos
Output:
Are
You
Return the address using str +
start_index and do pos++
Assignment 7
A r e 0 y o u 0 o k a y 0
; : 0
str
delim
0 1 2 3 4 5 6 7 8 9 10 11 12
start_index
 Input: str = “Are;you:okay”
delim = “;:”
pos
Output:
Are
You
Assignment 7
A r e 0 y o u 0 o k a y 0
; : 0
str
delim
0 1 2 3 4 5 6 7 8 9 10 11 12
start_index
 Input: str = “Are;you:okay”
delim = “;:”
pos
Output:
Are
You
Assignment 7
A r e 0 y o u 0 o k a y 0
; : 0
str
delim
0 1 2 3 4 5 6 7 8 9 10 11 12
start_index
 Input: str = “Are;you:okay”
delim = “;:”
pos
Output:
Are
You
Assignment 7
A r e 0 y o u 0 o k a y 0
; : 0
str
delim
0 1 2 3 4 5 6 7 8 9 10 11 12
start_index
 Input: str = “Are;you:okay”
delim = “;:”
pos
Output:
Are
You
Assignment 7
A r e 0 y o u 0 o k a y 0
; : 0
str
delim
0 1 2 3 4 5 6 7 8 9 10 11 12
start_index
 Input: str = “Are;you:okay”
delim = “;:”
pos
Output:
Are
You
Assignment 7
A r e 0 y o u 0 o k a y 0
; : 0
str
delim
0 1 2 3 4 5 6 7 8 9 10 11 12
start_index
 Input: str = “Are;you:okay”
delim = “;:”
pos
Output:
Are
You
Assignment 7
A r e 0 y o u 0 o k a y 0
; : 0
str
delim
0 1 2 3 4 5 6 7 8 9 10 11 12
start_index
 Input: str = “Are;you:okay”
delim = “;:”
pos
Output:
Are
You
Assignment 7
A r e 0 y o u 0 o k a y 0
; : 0
str
delim
0 1 2 3 4 5 6 7 8 9 10 11 12
start_index
 Input: str = “Are;you:okay”
delim = “;:”
pos
Output:
Are
You
Assignment 7
A r e 0 y o u 0 o k a y 0
; : 0
str
delim
0 1 2 3 4 5 6 7 8 9 10 11 12
start_index
 Input: str = “Are;you:okay”
delim = “;:”
pos
Output:
Are
You
okay
Return the address using str +
start_index
Assignment 7
Sample execution:-
Assignment 7
Sample execution:-
Assignment 7
Sample execution:-
Assignment 7
Pre-requisites:-
Assignment 7
Pre-requisites:-
⮚Strings
Assignment 7
Pre-requisites:-
⮚Strings
⮚Storage Classes
Assignment 7
Pre-requisites:-
⮚Strings
⮚Storage Classes
⮚Pointers
Assignment 7
Pre-requisites:-
⮚Strings
⮚Storage Classes
⮚Pointers
Objective:-
Assignment 7
Pre-requisites:-
⮚Strings
⮚Storage Classes
⮚Pointers
Objective:-
To understand the concept of String functions.
Team Emertxe
Thank you

Weitere ähnliche Inhalte

Ähnlich wie 07_strtok.pdf

Lecture 22
Lecture 22Lecture 22
Lecture 22
rhshriva
 
Advanced perl finer points ,pack&unpack,eval,files
Advanced perl   finer points ,pack&unpack,eval,filesAdvanced perl   finer points ,pack&unpack,eval,files
Advanced perl finer points ,pack&unpack,eval,files
Shankar D
 
C Programming Strings.docx
C Programming Strings.docxC Programming Strings.docx
C Programming Strings.docx
8759000398
 
Bioinformatica: Leggere file con Perl, e introduzione alle espressioni regola...
Bioinformatica: Leggere file con Perl, e introduzione alle espressioni regola...Bioinformatica: Leggere file con Perl, e introduzione alle espressioni regola...
Bioinformatica: Leggere file con Perl, e introduzione alle espressioni regola...
Andrea Telatin
 
OSS BarCamp Mumbai - JSON Presentation and Demo
OSS BarCamp Mumbai - JSON Presentation and DemoOSS BarCamp Mumbai - JSON Presentation and Demo
OSS BarCamp Mumbai - JSON Presentation and Demo
Ketan Khairnar
 

Ähnlich wie 07_strtok.pdf (20)

05 c++-strings
05 c++-strings05 c++-strings
05 c++-strings
 
Lecture 22
Lecture 22Lecture 22
Lecture 22
 
JSUG - Scala Lightning Talk by Michael Greifeneder
JSUG - Scala Lightning Talk by Michael GreifenederJSUG - Scala Lightning Talk by Michael Greifeneder
JSUG - Scala Lightning Talk by Michael Greifeneder
 
Advanced perl finer points ,pack&unpack,eval,files
Advanced perl   finer points ,pack&unpack,eval,filesAdvanced perl   finer points ,pack&unpack,eval,files
Advanced perl finer points ,pack&unpack,eval,files
 
14 strings
14 strings14 strings
14 strings
 
Knit One, Compute One - YOW! Night Perth
Knit One, Compute One - YOW! Night PerthKnit One, Compute One - YOW! Night Perth
Knit One, Compute One - YOW! Night Perth
 
SWP - A Generic Language Parser
SWP - A Generic Language ParserSWP - A Generic Language Parser
SWP - A Generic Language Parser
 
Strings and Characters
Strings and CharactersStrings and Characters
Strings and Characters
 
07_triangle_pattern.pdf
07_triangle_pattern.pdf07_triangle_pattern.pdf
07_triangle_pattern.pdf
 
C Programming Strings.docx
C Programming Strings.docxC Programming Strings.docx
C Programming Strings.docx
 
How to Vim - for beginners
How to Vim - for beginnersHow to Vim - for beginners
How to Vim - for beginners
 
L-13 part2-string handling.pptx
L-13 part2-string handling.pptxL-13 part2-string handling.pptx
L-13 part2-string handling.pptx
 
09_isalnum.pdf
09_isalnum.pdf09_isalnum.pdf
09_isalnum.pdf
 
The $path to knowledge: What little it take to unit-test Perl.
The $path to knowledge: What little it take to unit-test Perl.The $path to knowledge: What little it take to unit-test Perl.
The $path to knowledge: What little it take to unit-test Perl.
 
Brief instruction on backprop
Brief instruction on backpropBrief instruction on backprop
Brief instruction on backprop
 
Zend framework 05 - ajax, json and j query
Zend framework 05 - ajax, json and j queryZend framework 05 - ajax, json and j query
Zend framework 05 - ajax, json and j query
 
13 Strings and Text Processing
13 Strings and Text Processing13 Strings and Text Processing
13 Strings and Text Processing
 
CS.3.Arrays.pdf
CS.3.Arrays.pdfCS.3.Arrays.pdf
CS.3.Arrays.pdf
 
Bioinformatica: Leggere file con Perl, e introduzione alle espressioni regola...
Bioinformatica: Leggere file con Perl, e introduzione alle espressioni regola...Bioinformatica: Leggere file con Perl, e introduzione alle espressioni regola...
Bioinformatica: Leggere file con Perl, e introduzione alle espressioni regola...
 
OSS BarCamp Mumbai - JSON Presentation and Demo
OSS BarCamp Mumbai - JSON Presentation and DemoOSS BarCamp Mumbai - JSON Presentation and Demo
OSS BarCamp Mumbai - JSON Presentation and Demo
 

Mehr von Emertxe Information Technologies Pvt Ltd

Mehr von Emertxe Information Technologies Pvt Ltd (20)

premium post (1).pdf
premium post (1).pdfpremium post (1).pdf
premium post (1).pdf
 
Career Transition (1).pdf
Career Transition (1).pdfCareer Transition (1).pdf
Career Transition (1).pdf
 
10_isxdigit.pdf
10_isxdigit.pdf10_isxdigit.pdf
10_isxdigit.pdf
 
01_student_record.pdf
01_student_record.pdf01_student_record.pdf
01_student_record.pdf
 
02_swap.pdf
02_swap.pdf02_swap.pdf
02_swap.pdf
 
01_sizeof.pdf
01_sizeof.pdf01_sizeof.pdf
01_sizeof.pdf
 
07_product_matrix.pdf
07_product_matrix.pdf07_product_matrix.pdf
07_product_matrix.pdf
 
06_sort_names.pdf
06_sort_names.pdf06_sort_names.pdf
06_sort_names.pdf
 
05_fragments.pdf
05_fragments.pdf05_fragments.pdf
05_fragments.pdf
 
04_magic_square.pdf
04_magic_square.pdf04_magic_square.pdf
04_magic_square.pdf
 
03_endianess.pdf
03_endianess.pdf03_endianess.pdf
03_endianess.pdf
 
02_variance.pdf
02_variance.pdf02_variance.pdf
02_variance.pdf
 
01_memory_manager.pdf
01_memory_manager.pdf01_memory_manager.pdf
01_memory_manager.pdf
 
09_nrps.pdf
09_nrps.pdf09_nrps.pdf
09_nrps.pdf
 
11_pangram.pdf
11_pangram.pdf11_pangram.pdf
11_pangram.pdf
 
10_combinations.pdf
10_combinations.pdf10_combinations.pdf
10_combinations.pdf
 
08_squeeze.pdf
08_squeeze.pdf08_squeeze.pdf
08_squeeze.pdf
 
06_reverserec.pdf
06_reverserec.pdf06_reverserec.pdf
06_reverserec.pdf
 
05_reverseiter.pdf
05_reverseiter.pdf05_reverseiter.pdf
05_reverseiter.pdf
 
04_itoa.pdf
04_itoa.pdf04_itoa.pdf
04_itoa.pdf
 

Kürzlich hochgeladen

1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdf
QucHHunhnh
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
QucHHunhnh
 
Spellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please PractiseSpellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please Practise
AnaAcapella
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
ciinovamais
 
Vishram Singh - Textbook of Anatomy Upper Limb and Thorax.. Volume 1 (1).pdf
Vishram Singh - Textbook of Anatomy  Upper Limb and Thorax.. Volume 1 (1).pdfVishram Singh - Textbook of Anatomy  Upper Limb and Thorax.. Volume 1 (1).pdf
Vishram Singh - Textbook of Anatomy Upper Limb and Thorax.. Volume 1 (1).pdf
ssuserdda66b
 

Kürzlich hochgeladen (20)

Micro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdfMicro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdf
 
Sociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning ExhibitSociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning Exhibit
 
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxBasic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdf
 
Spatium Project Simulation student brief
Spatium Project Simulation student briefSpatium Project Simulation student brief
Spatium Project Simulation student brief
 
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
 
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdf
 
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptxSKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
 
Towards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptxTowards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptx
 
Spellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please PractiseSpellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please Practise
 
Making communications land - Are they received and understood as intended? we...
Making communications land - Are they received and understood as intended? we...Making communications land - Are they received and understood as intended? we...
Making communications land - Are they received and understood as intended? we...
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
 
ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.
 
Vishram Singh - Textbook of Anatomy Upper Limb and Thorax.. Volume 1 (1).pdf
Vishram Singh - Textbook of Anatomy  Upper Limb and Thorax.. Volume 1 (1).pdfVishram Singh - Textbook of Anatomy  Upper Limb and Thorax.. Volume 1 (1).pdf
Vishram Singh - Textbook of Anatomy Upper Limb and Thorax.. Volume 1 (1).pdf
 
Graduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - EnglishGraduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - English
 
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
 
Dyslexia AI Workshop for Slideshare.pptx
Dyslexia AI Workshop for Slideshare.pptxDyslexia AI Workshop for Slideshare.pptx
Dyslexia AI Workshop for Slideshare.pptx
 
Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)
 

07_strtok.pdf

  • 1. Team Emertxe Strings and Storage Classes
  • 4. Assignment 7 WAP to implement strtok function
  • 5. Assignment 7 WAP to implement strtok function Input:
  • 6. Assignment 7 WAP to implement strtok function Input: Read two Strings.
  • 7. Assignment 7 WAP to implement strtok function Input: Read two Strings. Output:
  • 8. Assignment 7 WAP to implement strtok function Input: Read two Strings. Output: Print tokens from string.
  • 9. Assignment 7 What is strtok() function?
  • 10. Assignment 7 What is strtok() function?  The strtok() function breaks a string into a sequence of zero or more nonempty tokens.  On the first call to strtok(), the string to be parsed should be specified in str. In each subsequent call that should parse the same string, str must be NULL.
  • 11. Assignment 7 What is strtok() function?  The strtok() function breaks a string into a sequence of zero or more nonempty tokens.  On the first call to strtok(), the string to be parsed should be specified in str. In each subsequent call that should parse the same string, str must be NULL. Prototype: char *strtok(char *str, const char *delim);
  • 12. Assignment 7 Let’s understand how strtok() works:
  • 13. Assignment 7 Let’s understand how strtok() works:
  • 14. Assignment 7 Let’s understand how strtok() works: What will be printed?
  • 15. Assignment 7 Let’s understand how strtok() works: “Are” will be printed O/p of the program: Are
  • 16. Assignment 7 Let’s understand how strtok() works: What will be printed?
  • 17. Assignment 7 Let’s understand how strtok() works: “Are” will be printed “Are” will be printed O/p of the program: Are Are
  • 18. Assignment 7 Let’s understand how strtok() works: But, the next token should be printed is “you” “Are” will be printed “Are” will be printed O/p of the program: Are Are
  • 19. Assignment 7 Let’s understand how strtok() works: What will be printed? What will be printed?
  • 20. Assignment 7 Let’s understand how strtok() works: “you” will be printed “Are” will be printed O/p of the program: Are you
  • 21. Assignment 7 Let’s understand how strtok() works: O/p of the program: Are you How will you print the remaining tokens?
  • 22. Assignment 7 Let’s understand how strtok() works: What is the output?
  • 23. Assignment 7 Let’s understand how strtok() works: O/p of the program: Are You okay
  • 24. Assignment 7 How to implement your own strtok() function?
  • 25. Assignment 7 How to implement your own strtok() function?  Input: str = “Are;you:okay” delim = “;:” A r e ; y o u : o k a y 0 ; : 0 str delim String containing delimiters, these delimiters has to be matched with each and every character of str
  • 26. Assignment 7 A r e ; y o u : o k a y 0 ; : 0 str delim 0 1 2 3 4 5 6 7 8 9 10 11 12 start_index  Input: str = “Are;you:okay” delim = “;:” pos
  • 27. Assignment 7 A r e ; y o u : o k a y 0 ; : 0 str delim 0 1 2 3 4 5 6 7 8 9 10 11 12 start_index  Input: str = “Are;you:okay” delim = “;:” pos
  • 28. Assignment 7 A r e ; y o u : o k a y 0 ; : 0 str delim 0 1 2 3 4 5 6 7 8 9 10 11 12 start_index  Input: str = “Are;you:okay” delim = “;:” pos
  • 29. Assignment 7 A r e ; y o u : o k a y 0 ; : 0 str delim 0 1 2 3 4 5 6 7 8 9 10 11 12 start_index  Input: str = “Are;you:okay” delim = “;:” pos
  • 30. Assignment 7 A r e ; y o u : o k a y 0 ; : 0 str delim 0 1 2 3 4 5 6 7 8 9 10 11 12 start_index  Input: str = “Are;you:okay” delim = “;:” pos
  • 31. Assignment 7 A r e ; y o u : o k a y 0 ; : 0 str delim 0 1 2 3 4 5 6 7 8 9 10 11 12 start_index  Input: str = “Are;you:okay” delim = “;:” pos
  • 32. Assignment 7 A r e ; y o u : o k a y 0 ; : 0 str delim 0 1 2 3 4 5 6 7 8 9 10 11 12 start_index  Input: str = “Are;you:okay” delim = “;:” pos Here at pos 3, delimiter is encountered, so overwrite that byte with ‘0’
  • 33. Assignment 7 A r e 0 y o u : o k a y 0 ; : 0 str delim 0 1 2 3 4 5 6 7 8 9 10 11 12 start_index  Input: str = “Are;you:okay” delim = “;:” pos Return the address using str + start_index and do pos++
  • 34. Assignment 7 A r e 0 y o u : o k a y 0 ; : 0 str delim 0 1 2 3 4 5 6 7 8 9 10 11 12 start_index  Input: str = “Are;you:okay” delim = “;:” pos Return the address using str + start_index and do pos++ Output: Are
  • 35. Assignment 7 A r e 0 y o u : o k a y 0 ; : 0 str delim 0 1 2 3 4 5 6 7 8 9 10 11 12 start_index  Input: str = “Are;you:okay” delim = “;:” pos Output: Are
  • 36. Assignment 7 A r e 0 y o u : o k a y 0 ; : 0 str delim 0 1 2 3 4 5 6 7 8 9 10 11 12 start_index  Input: str = “Are;you:okay” delim = “;:” pos Output: Are
  • 37. Assignment 7 A r e 0 y o u : o k a y 0 ; : 0 str delim 0 1 2 3 4 5 6 7 8 9 10 11 12 start_index  Input: str = “Are;you:okay” delim = “;:” pos Output: Are
  • 38. Assignment 7 A r e 0 y o u : o k a y 0 ; : 0 str delim 0 1 2 3 4 5 6 7 8 9 10 11 12 start_index  Input: str = “Are;you:okay” delim = “;:” pos Output: Are
  • 39. Assignment 7 A r e 0 y o u : o k a y 0 ; : 0 str delim 0 1 2 3 4 5 6 7 8 9 10 11 12 start_index  Input: str = “Are;you:okay” delim = “;:” pos Output: Are
  • 40. Assignment 7 A r e 0 y o u : o k a y 0 ; : 0 str delim 0 1 2 3 4 5 6 7 8 9 10 11 12 start_index  Input: str = “Are;you:okay” delim = “;:” pos Output: Are
  • 41. Assignment 7 A r e 0 y o u : o k a y 0 ; : 0 str delim 0 1 2 3 4 5 6 7 8 9 10 11 12 start_index  Input: str = “Are;you:okay” delim = “;:” pos Output: Are
  • 42. Assignment 7 A r e 0 y o u : o k a y 0 ; : 0 str delim 0 1 2 3 4 5 6 7 8 9 10 11 12 start_index  Input: str = “Are;you:okay” delim = “;:” pos Output: Are Here at pos 7, delimiter is encountered, so overwrite that byte with ‘0’
  • 43. Assignment 7 A r e 0 y o u 0 o k a y 0 ; : 0 str delim 0 1 2 3 4 5 6 7 8 9 10 11 12 start_index  Input: str = “Are;you:okay” delim = “;:” pos Output: Are You Return the address using str + start_index and do pos++
  • 44. Assignment 7 A r e 0 y o u 0 o k a y 0 ; : 0 str delim 0 1 2 3 4 5 6 7 8 9 10 11 12 start_index  Input: str = “Are;you:okay” delim = “;:” pos Output: Are You
  • 45. Assignment 7 A r e 0 y o u 0 o k a y 0 ; : 0 str delim 0 1 2 3 4 5 6 7 8 9 10 11 12 start_index  Input: str = “Are;you:okay” delim = “;:” pos Output: Are You
  • 46. Assignment 7 A r e 0 y o u 0 o k a y 0 ; : 0 str delim 0 1 2 3 4 5 6 7 8 9 10 11 12 start_index  Input: str = “Are;you:okay” delim = “;:” pos Output: Are You
  • 47. Assignment 7 A r e 0 y o u 0 o k a y 0 ; : 0 str delim 0 1 2 3 4 5 6 7 8 9 10 11 12 start_index  Input: str = “Are;you:okay” delim = “;:” pos Output: Are You
  • 48. Assignment 7 A r e 0 y o u 0 o k a y 0 ; : 0 str delim 0 1 2 3 4 5 6 7 8 9 10 11 12 start_index  Input: str = “Are;you:okay” delim = “;:” pos Output: Are You
  • 49. Assignment 7 A r e 0 y o u 0 o k a y 0 ; : 0 str delim 0 1 2 3 4 5 6 7 8 9 10 11 12 start_index  Input: str = “Are;you:okay” delim = “;:” pos Output: Are You
  • 50. Assignment 7 A r e 0 y o u 0 o k a y 0 ; : 0 str delim 0 1 2 3 4 5 6 7 8 9 10 11 12 start_index  Input: str = “Are;you:okay” delim = “;:” pos Output: Are You
  • 51. Assignment 7 A r e 0 y o u 0 o k a y 0 ; : 0 str delim 0 1 2 3 4 5 6 7 8 9 10 11 12 start_index  Input: str = “Are;you:okay” delim = “;:” pos Output: Are You
  • 52. Assignment 7 A r e 0 y o u 0 o k a y 0 ; : 0 str delim 0 1 2 3 4 5 6 7 8 9 10 11 12 start_index  Input: str = “Are;you:okay” delim = “;:” pos Output: Are You okay Return the address using str + start_index