SlideShare a Scribd company logo
2
Most read
3
Most read
11
Most read
Submited by:
Md: Aliul Kadir akib
Daffodil international university
mail:aliulkadir@gmail.com
Welcome to CSE PRESENTATION
Topics:
Operation On String
1.Strings
2.Memory Storage for a String
3.Input/Output of a String
Right and Left Justification of Strings
An Example of Manipulating String with scanf and
printf
String Library Functions
Some String Functions from String.h
Functions strcat and strlen
Character Analysis and Conversion
CONTENT
Strings
• C implements the stringstring data structure using
arrays of type char.
• You have already used the string extensively.
– printf(“This program is terminated!n”);
• Since stringstring is an array, the declaration of a
string is the same as declaring a char array.
– char string_var[30];
– char string_var[20] = “Initial value”;
Memory Storage for a String
• The string is always ended with a nullnull
charactercharacter ‘0’‘0’.
• The characters after the null character are
ignored.
• e.g., char str[20] = “Initial value”;
n i t i a l v a l u e ? ? …I 00
[0] [13]
Memory Storage for a String
• An array of strings is a two-dimensional array of
characters in which each row is one string.
– char names[People][Length];
– char month[5][10] = {“January”,
“February”, “March”, “April”,
“May”};
Input/Output of a String
• The placeholder %s%s is used to represent string
arguments in printf and scanf.
– printf(“Topic: %sn”, string_var);
• The string can be right-justified by placing a
positive number in the placeholder.
– printf(“%8s%8s”, str);
• The string can be left-justified by placing a
negative number in the placeholder.
– Printf(“%-8s%-8s”, str);
Right and Left Justification of
Strings
The “%8s%8s” placeholder displays a string which is right-
justified and in 8-columns width.
If the actual string is longer than the width, the displayed field
is expanded with no padding.
Copyright ©2004 Pearson Addison-Wesley. All rights reserved.
An Example of Manipulating String
with scanf and printf
The dept is the initial memory
address of the string argument. Thus
we don’t apply the & operator on it.
String Library Functions
• The string can not be copied by the assignment
operator ‘=’.
– e..g, “str = “Test String”” is not valid.
• C provides string manipulating functions in the
“string.h” library.
– The complete list of these functions can be found in
Appendix B of the textbook.
Some String Functions from String.h
Function Purpose Example
strcpy Makes a copy of a
string
strcpy(s1, “Hi”);
strcat Appends a string to the
end of another string
strcat(s1, “more”);
strcmp Compare two strings
alphabetically
strcmp(s1, “Hu”);
strlen Returns the number of
characters in a string
strlen(“Hi”)
returns 2.
strtok Breaks a string into
tokens by delimiters.
strtok(“Hi, Chao”,
“ ,”);
Functions strcat and strlen
• Functions strcat and strncat concatenate
the fist string argument with the second string
argument.
– strcat(dest, “more..”);
– strncat(dest, “more..”, 3);
• Function strlen is often used to check the
length of a string (i.e., the number of characters
before the fist null character).
– e.g., dest[6] = “Hello”;
strncat(dest, “more”, 5-strlen(dest));
dest[5] = ‘0’;
Character Analysis and Conversion
• The <ctype.h><ctype.h> library defines facilities for character
analysis and conversion.
Functions Description
isalpha Check if the argument is a letter
isdigit Check if the argument is one of the ten digits
isspace Check if argument is a space, newline or tab.
tolower Converts the lowercase letters in the
argument to upper case letters.
Operation on string presentation

More Related Content

PPTX
Variables in C++, data types in c++
PPTX
Input and Output In C Language
PPTX
Array and string
PPT
Function overloading(c++)
PDF
Introduction to c++ ppt 1
PPTX
C tokens
PDF
Loops and conditional statements
PPTX
Looping statements in C
Variables in C++, data types in c++
Input and Output In C Language
Array and string
Function overloading(c++)
Introduction to c++ ppt 1
C tokens
Loops and conditional statements
Looping statements in C

What's hot (20)

PPTX
Functions in c language
PPT
Variables in C Programming
PPTX
Control structures in c++
PPTX
Method overloading
PPTX
Character Arrays and strings in c language
PPTX
C++ string
PPT
Strings
PPTX
Steps for c program execution
PPT
Constants in C Programming
PPTX
Variables in C and C++ Language
PPTX
Control statements in c
PPTX
Exception handling c++
PPTX
Pointers in c language
PPTX
data types in C programming
PPTX
Functions in c
PDF
Constructors and Destructors
PDF
Lecture 01 introduction to compiler
PPTX
Introduction to problem solving in C
PPTX
Data types in python
Functions in c language
Variables in C Programming
Control structures in c++
Method overloading
Character Arrays and strings in c language
C++ string
Strings
Steps for c program execution
Constants in C Programming
Variables in C and C++ Language
Control statements in c
Exception handling c++
Pointers in c language
data types in C programming
Functions in c
Constructors and Destructors
Lecture 01 introduction to compiler
Introduction to problem solving in C
Data types in python
Ad

Similar to Operation on string presentation (20)

PPT
Strings(2007)
PDF
[ITP - Lecture 17] Strings in C/C++
PDF
Strings in c mrs.sowmya jyothi
PPT
PPTX
Strings CPU GTU
PPTX
fundamentals of c programming_String.pptx
PDF
STRINGS IN C MRS.SOWMYA JYOTHI.pdf
PPT
Strings in c
PDF
0-Slot21-22-Strings.pdf
PPTX
24_2-String and String Library.pptx
PPTX
Programming in C - Fundamental Study of Strings
PPTX
Strings in C
PPTX
Presentation more c_programmingcharacter_and_string_handling_
PDF
Character Array and String
PDF
strings-150319180934-conversion-gate01.pdf
PDF
Principals of Programming in CModule -5.pdfModule-4.pdf
PPT
CP-STRING.ppt
PPT
CP-STRING (1).ppt
PPT
CP-STRING.ppt
Strings(2007)
[ITP - Lecture 17] Strings in C/C++
Strings in c mrs.sowmya jyothi
Strings CPU GTU
fundamentals of c programming_String.pptx
STRINGS IN C MRS.SOWMYA JYOTHI.pdf
Strings in c
0-Slot21-22-Strings.pdf
24_2-String and String Library.pptx
Programming in C - Fundamental Study of Strings
Strings in C
Presentation more c_programmingcharacter_and_string_handling_
Character Array and String
strings-150319180934-conversion-gate01.pdf
Principals of Programming in CModule -5.pdfModule-4.pdf
CP-STRING.ppt
CP-STRING (1).ppt
CP-STRING.ppt
Ad

Recently uploaded (20)

PDF
SM_6th-Sem__Cse_Internet-of-Things.pdf IOT
PDF
Operating System & Kernel Study Guide-1 - converted.pdf
PPTX
Welding lecture in detail for understanding
PPTX
FINAL REVIEW FOR COPD DIANOSIS FOR PULMONARY DISEASE.pptx
PPTX
bas. eng. economics group 4 presentation 1.pptx
PDF
The CXO Playbook 2025 – Future-Ready Strategies for C-Suite Leaders Cerebrai...
PPT
Mechanical Engineering MATERIALS Selection
PDF
Model Code of Practice - Construction Work - 21102022 .pdf
PPT
Project quality management in manufacturing
PPTX
CH1 Production IntroductoryConcepts.pptx
PPTX
Lecture Notes Electrical Wiring System Components
DOCX
ASol_English-Language-Literature-Set-1-27-02-2023-converted.docx
PPTX
M Tech Sem 1 Civil Engineering Environmental Sciences.pptx
PPTX
Foundation to blockchain - A guide to Blockchain Tech
PDF
PRIZ Academy - 9 Windows Thinking Where to Invest Today to Win Tomorrow.pdf
PDF
Enhancing Cyber Defense Against Zero-Day Attacks using Ensemble Neural Networks
PDF
Digital Logic Computer Design lecture notes
PDF
composite construction of structures.pdf
PDF
PPT on Performance Review to get promotions
PPTX
UNIT 4 Total Quality Management .pptx
SM_6th-Sem__Cse_Internet-of-Things.pdf IOT
Operating System & Kernel Study Guide-1 - converted.pdf
Welding lecture in detail for understanding
FINAL REVIEW FOR COPD DIANOSIS FOR PULMONARY DISEASE.pptx
bas. eng. economics group 4 presentation 1.pptx
The CXO Playbook 2025 – Future-Ready Strategies for C-Suite Leaders Cerebrai...
Mechanical Engineering MATERIALS Selection
Model Code of Practice - Construction Work - 21102022 .pdf
Project quality management in manufacturing
CH1 Production IntroductoryConcepts.pptx
Lecture Notes Electrical Wiring System Components
ASol_English-Language-Literature-Set-1-27-02-2023-converted.docx
M Tech Sem 1 Civil Engineering Environmental Sciences.pptx
Foundation to blockchain - A guide to Blockchain Tech
PRIZ Academy - 9 Windows Thinking Where to Invest Today to Win Tomorrow.pdf
Enhancing Cyber Defense Against Zero-Day Attacks using Ensemble Neural Networks
Digital Logic Computer Design lecture notes
composite construction of structures.pdf
PPT on Performance Review to get promotions
UNIT 4 Total Quality Management .pptx

Operation on string presentation

  • 1. Submited by: Md: Aliul Kadir akib Daffodil international university mail:aliulkadir@gmail.com Welcome to CSE PRESENTATION Topics: Operation On String
  • 2. 1.Strings 2.Memory Storage for a String 3.Input/Output of a String Right and Left Justification of Strings An Example of Manipulating String with scanf and printf String Library Functions Some String Functions from String.h Functions strcat and strlen Character Analysis and Conversion CONTENT
  • 3. Strings • C implements the stringstring data structure using arrays of type char. • You have already used the string extensively. – printf(“This program is terminated!n”); • Since stringstring is an array, the declaration of a string is the same as declaring a char array. – char string_var[30]; – char string_var[20] = “Initial value”;
  • 4. Memory Storage for a String • The string is always ended with a nullnull charactercharacter ‘0’‘0’. • The characters after the null character are ignored. • e.g., char str[20] = “Initial value”; n i t i a l v a l u e ? ? …I 00 [0] [13]
  • 5. Memory Storage for a String • An array of strings is a two-dimensional array of characters in which each row is one string. – char names[People][Length]; – char month[5][10] = {“January”, “February”, “March”, “April”, “May”};
  • 6. Input/Output of a String • The placeholder %s%s is used to represent string arguments in printf and scanf. – printf(“Topic: %sn”, string_var); • The string can be right-justified by placing a positive number in the placeholder. – printf(“%8s%8s”, str); • The string can be left-justified by placing a negative number in the placeholder. – Printf(“%-8s%-8s”, str);
  • 7. Right and Left Justification of Strings The “%8s%8s” placeholder displays a string which is right- justified and in 8-columns width. If the actual string is longer than the width, the displayed field is expanded with no padding.
  • 8. Copyright ©2004 Pearson Addison-Wesley. All rights reserved. An Example of Manipulating String with scanf and printf The dept is the initial memory address of the string argument. Thus we don’t apply the & operator on it.
  • 9. String Library Functions • The string can not be copied by the assignment operator ‘=’. – e..g, “str = “Test String”” is not valid. • C provides string manipulating functions in the “string.h” library. – The complete list of these functions can be found in Appendix B of the textbook.
  • 10. Some String Functions from String.h Function Purpose Example strcpy Makes a copy of a string strcpy(s1, “Hi”); strcat Appends a string to the end of another string strcat(s1, “more”); strcmp Compare two strings alphabetically strcmp(s1, “Hu”); strlen Returns the number of characters in a string strlen(“Hi”) returns 2. strtok Breaks a string into tokens by delimiters. strtok(“Hi, Chao”, “ ,”);
  • 11. Functions strcat and strlen • Functions strcat and strncat concatenate the fist string argument with the second string argument. – strcat(dest, “more..”); – strncat(dest, “more..”, 3); • Function strlen is often used to check the length of a string (i.e., the number of characters before the fist null character). – e.g., dest[6] = “Hello”; strncat(dest, “more”, 5-strlen(dest)); dest[5] = ‘0’;
  • 12. Character Analysis and Conversion • The <ctype.h><ctype.h> library defines facilities for character analysis and conversion. Functions Description isalpha Check if the argument is a letter isdigit Check if the argument is one of the ten digits isspace Check if argument is a space, newline or tab. tolower Converts the lowercase letters in the argument to upper case letters.