TABLE OF CONTENTS
Our team
Introduction to
strings
String manipulation
functions
String input and
output
1
2
3
4
String comparison
functions
5
Declaring and
initializing strings
6
Mugdho Saha
Team Member
Sumaiya Akter
Team Member
Soumitra
Rakshit
Group
Leader
Mahbuba Jhuma
Team Member
Md. Rahid Hossain
Team Member
OUR
TEAM
INTRODUCTI
ON TO
STRINGS
C does not have a String type to easily
create string variables. Instead, you must
use the char type and create an array of
characters to make a string in C
WHAT ARE
STRINGS?
Strings are used for storing text/characters.
For example, "Hello World" is a string of
characters.
OUTPUT THE
STRINGS
To output the string, you can use the printf()
function together with the format specifier
%s to tell C that we are now working with
strings:
Note that you have to use
double quotes (" ")
To use them, you must include the
<string.h> header file in your program.
STRING
FUNCTIONS
C also has many useful string functions,
which can be used to perform certain
operations on strings.
STRINGS - SPECIAL CHARACTERS
Because strings must be written within quotes, C will
misunderstand this string, and generate an error:
The solution to avoid this problem, is to use the
backslash escape character.
The backslash () escape character turns special
characters into string characters.
Some popular escape
characters in C are:
For example, the sequence ' inserts a
single quote in a string:
STRING
MANIPULATI
ON
FUNCTIONS
STRING MANIPULATION FUNCTIONS
String manipulation functions are a set of operations
or functions provided by programming languages
and libraries to perform various tasks on strings.
These tasks can include tasks such as finding the
length of a string, copying one string to another,
concatenating strings, comparing strings, searching
for substrings, and more.
USE STRLEN() TO FIND THE LENGTH OF A
STRING?
In C and C++ (and some other languages), you can
use the strlen() function to find the length of a null-
terminated string. Here's how to use it:
This code snippet includes the <string.h> header,
which provides the strlen() function. It calculates
the length of the string myString (including all
characters except the null terminator) and stores it
in the length variable.
USE STRCPY() TO COPY ONE STRING TO
ANOTHER
In C and C++, you can use the strcpy() function to
copy one string to another. Here's how to use it:
The <string.h> header is again included, and
strcpy() is used to copy the content of the source
string into the destination string. Make sure that
the destination array is large enough to
accommodate the source string, including the
STRING
INPUT AND
OUTPUT
READ A STRING FROM THE USER
There are two main ways to read a string from the
user in a C program: Using the scanf() function &
Using the fgets() function. Which method you choose
to use depends on your specific needs. If you only
need to read a single line of input from the user,
then the fgets() function is a good option. If you
need to read multiple lines of input from the user,
then the scanf() function is a better option.
DISPLAY A STRING ON THE
SCREEN
This variable will store the string that you want to
display. The string variable must be declared as an
array of characters, with enough space to store the
string plus the null character (0). You can also use
the puts() function to display a string on the screen.
The puts() function takes a pointer to a string as its
argument and prints the string to the standard
output device
DIFFERENCE BETWEEN PRINTF()
AND PUTS()
STRING
COMPARISO
N
FUNCTIONS
STRING COMPARISON
String comparison is a fundamental operation in
programming, allowing us to determine the equality
or ordering of strings. These functions play a crucial
role in various programming languages and can be
used to perform powerful string manipulations.
WHAT ARE STRING COMPARISON
FUNCTIONS?
String comparison functions are built-in functions in
programming languages that enable us to compare
strings. They typically return an integer value
indicating the relationship between two strings. The
result can be used to determine if the strings are
equal, or if one string is greater or lesser than the
other based on lexicographical order.
USE STRCMP() TO COMPARE TWO
STRINGS
strcmp() - Comparing two strings: The strcmp()
function is widely used for string comparison. It
takes two string arguments and returns an integer
value.
USE STRCMP() TO COMPARE TWO
STRINGS
The strcmp() function is widely used for string
comparison. It takes two string arguments and
returns an integer value. If the two strings are equal,
strcmp() returns 0. If the first string is
lexicographically less than the second string,
strcmp() returns a negative value .If the first string is
lexicographically greater than the second string,
strcmp() returns a positive value.
DIFFERENCE BETWEEN STRCMP() AND
`STRNCMP()
DECLARING
AND
INITIALIZING
STRINGS
DECLARE A STRING
Declaring a string in C is as simple as declaring a
one-dimensional array.
in the above syntax str_name is any name given
to the string variable and size is used to define
the length of the string, i.e the number of
characters strings will store.
INITIALIZE A STRING
A string in C can be initialized in different ways.
Assigning a string literal without size, assigning a
string literal with a predefined size, assigning
character by character with size, Assigning character
by character without size.
DIFFERENCE BETWEEN DECLARATION AND
INITIALIZATION
In C, a declaration of a string is a statement that
introduces the name of the string to the compiler,
along with information about the type of data it will
hold. It does not allocate memory for the string.
On the other hand, initialization of a string is the
process of assigning an initial value to a variable at
the time of declaration.
It allocates memory for the string and initializes it wi
th a given value
CONCLUSIONS
C Strings are an essential part of the C
programming language. C Strings can be
declared, initialized, read, passed, and
manipulated using various functions and
operators. However, C Strings also have
some limitations, such as the lack of a built-
in string type, the risk of buffer overflow, and
the difficulty of handling Unicode characters.
THANK
YOU!

SPL PRESENTATION of string analysis.pptx

  • 2.
    TABLE OF CONTENTS Ourteam Introduction to strings String manipulation functions String input and output 1 2 3 4 String comparison functions 5 Declaring and initializing strings 6
  • 3.
    Mugdho Saha Team Member SumaiyaAkter Team Member Soumitra Rakshit Group Leader Mahbuba Jhuma Team Member Md. Rahid Hossain Team Member OUR TEAM
  • 4.
  • 5.
    C does nothave a String type to easily create string variables. Instead, you must use the char type and create an array of characters to make a string in C WHAT ARE STRINGS? Strings are used for storing text/characters. For example, "Hello World" is a string of characters.
  • 6.
    OUTPUT THE STRINGS To outputthe string, you can use the printf() function together with the format specifier %s to tell C that we are now working with strings: Note that you have to use double quotes (" ")
  • 7.
    To use them,you must include the <string.h> header file in your program. STRING FUNCTIONS C also has many useful string functions, which can be used to perform certain operations on strings.
  • 8.
    STRINGS - SPECIALCHARACTERS Because strings must be written within quotes, C will misunderstand this string, and generate an error: The solution to avoid this problem, is to use the backslash escape character. The backslash () escape character turns special characters into string characters.
  • 9.
    Some popular escape charactersin C are: For example, the sequence ' inserts a single quote in a string:
  • 10.
  • 11.
    STRING MANIPULATION FUNCTIONS Stringmanipulation functions are a set of operations or functions provided by programming languages and libraries to perform various tasks on strings. These tasks can include tasks such as finding the length of a string, copying one string to another, concatenating strings, comparing strings, searching for substrings, and more.
  • 12.
    USE STRLEN() TOFIND THE LENGTH OF A STRING? In C and C++ (and some other languages), you can use the strlen() function to find the length of a null- terminated string. Here's how to use it:
  • 13.
    This code snippetincludes the <string.h> header, which provides the strlen() function. It calculates the length of the string myString (including all characters except the null terminator) and stores it in the length variable.
  • 14.
    USE STRCPY() TOCOPY ONE STRING TO ANOTHER In C and C++, you can use the strcpy() function to copy one string to another. Here's how to use it:
  • 15.
    The <string.h> headeris again included, and strcpy() is used to copy the content of the source string into the destination string. Make sure that the destination array is large enough to accommodate the source string, including the
  • 16.
  • 17.
    READ A STRINGFROM THE USER There are two main ways to read a string from the user in a C program: Using the scanf() function & Using the fgets() function. Which method you choose to use depends on your specific needs. If you only need to read a single line of input from the user, then the fgets() function is a good option. If you need to read multiple lines of input from the user, then the scanf() function is a better option.
  • 18.
    DISPLAY A STRINGON THE SCREEN This variable will store the string that you want to display. The string variable must be declared as an array of characters, with enough space to store the string plus the null character (0). You can also use the puts() function to display a string on the screen. The puts() function takes a pointer to a string as its argument and prints the string to the standard output device
  • 19.
  • 20.
  • 21.
    STRING COMPARISON String comparisonis a fundamental operation in programming, allowing us to determine the equality or ordering of strings. These functions play a crucial role in various programming languages and can be used to perform powerful string manipulations.
  • 22.
    WHAT ARE STRINGCOMPARISON FUNCTIONS? String comparison functions are built-in functions in programming languages that enable us to compare strings. They typically return an integer value indicating the relationship between two strings. The result can be used to determine if the strings are equal, or if one string is greater or lesser than the other based on lexicographical order.
  • 23.
    USE STRCMP() TOCOMPARE TWO STRINGS strcmp() - Comparing two strings: The strcmp() function is widely used for string comparison. It takes two string arguments and returns an integer value.
  • 24.
    USE STRCMP() TOCOMPARE TWO STRINGS The strcmp() function is widely used for string comparison. It takes two string arguments and returns an integer value. If the two strings are equal, strcmp() returns 0. If the first string is lexicographically less than the second string, strcmp() returns a negative value .If the first string is lexicographically greater than the second string, strcmp() returns a positive value.
  • 25.
  • 26.
  • 27.
    DECLARE A STRING Declaringa string in C is as simple as declaring a one-dimensional array. in the above syntax str_name is any name given to the string variable and size is used to define the length of the string, i.e the number of characters strings will store.
  • 28.
    INITIALIZE A STRING Astring in C can be initialized in different ways. Assigning a string literal without size, assigning a string literal with a predefined size, assigning character by character with size, Assigning character by character without size.
  • 29.
    DIFFERENCE BETWEEN DECLARATIONAND INITIALIZATION In C, a declaration of a string is a statement that introduces the name of the string to the compiler, along with information about the type of data it will hold. It does not allocate memory for the string. On the other hand, initialization of a string is the process of assigning an initial value to a variable at the time of declaration. It allocates memory for the string and initializes it wi th a given value
  • 30.
    CONCLUSIONS C Strings arean essential part of the C programming language. C Strings can be declared, initialized, read, passed, and manipulated using various functions and operators. However, C Strings also have some limitations, such as the lack of a built- in string type, the risk of buffer overflow, and the difficulty of handling Unicode characters.
  • 31.