A MICRO PROJECT REPORT ON :-
STRING HANDLING FUNCTIONS
SUBMITTED BY :
1]SHRAVAN WAGH
2]VIKAS SARKATE
3]RUSHIKESH SURYAWANSHI
4] SARTHAK SHIRSATH
Under the guidance of :-
[Link]
LOKNETE GOPALRAOJI GULVE POLYTECHNIC
VILHOLI
LOKNETE GOPALRAOJI GULVE POLYTECHNIC
VILHOLI
CERTIFICATE
This Is To Clarify That
1] SHRAVAN WAGH
2] VIKAS SARKATE
3] RUSHIKESH SURYAWANSHI
4] SARTHAK SHIRSATH
Students of First Year ( Artificial Intelligence )
Were Examined in the Micro Project Entitled
Prof.A,C. Badgujar Prof.R.R. Joshi
Principal
Faculty Member
H.O.D
[Link]
INDEX
• INTRODUCTION
• APPLICATION
• ALGORITHM
• PROGRAM
• ADVANTAGES & DISADVANTAGES
• CONCLUSION
• REFERENCES
INTRODUCTION
String handling functions are operations in programming languages
that allow manipulation and management of strings (sequences of
characters). These functions provide a wide variety of methods to
search, modify, combine, or extract data from strings, making them
essential for tasks like text processing, data validation, and
communication with [Link] most programming languages, strings
are considered objects or data types, and each language typically
provides a set of built-in functions to handle common string-related
operations. Here are some common types of string functions you
might encounter:"
APPLICATION
• Creating a C programming project that involves string
handling functions can be both an interesting and
educational exercise. Below, I'll guide you through creating a
basic string handling application that includes a set of
custom string functions, demonstrating various string
manipulation techniques.
ALGORITHM
• Algorithm1. substring function:-
• Check if start and end indices are valid. - Create a
new string to store the substring. - Copy characters
from start to end indices from str to the new string. -
Return the new string.
• 2. strstr function:- Iterate through str to find the first
occurrence of substr. - Check if the current character
matches the first character of substr. - If a match is
found, check the remaining characters of substr. -
Return the index of the first occurrence of substr.
• 3. strrstr function: Iterate through str in reverse to
find the last occurrence of substr. - Check if the
current character matches the last character of substr.
• - If a match is found, check the remaining
characters of substr. - Return the index of the last
occurrence of substr.
• 4. strreplace function: - Iterate through str to find
all occurrences of old.
- Replace each occurrence of old with new. -
Return the modified string.
PROGRAM
• String Handling Fuctions
[Link](): Copies one string to another.
2. strcat(): Concatenates two strings .
3. strcmp(): Compares two strings
[Link](): Finds the first occurrence of a
character in a string.
[Link](): Finds the last occurrence of a
character in a string.
6. strstr(): Finds the first occurrence of a
substring in a string.
[Link](): Returns the length of a string.
• EXAMPLE PROGRAM
#include <stdio.h>
#include <string.h>
int main() {
char str1[] = "Hello";
char str2[] = "World";
// strlen()
printf("Length of str1: %d\n", strlen(str1));
// strcpy()
char dest[10];
strcpy(dest, str1);
printf("Copied string: %s\n", dest);
// strcat()
strcat(dest, str2);
printf("Concatenated string: %s\n", dest);
// strcmp()
int result = strcmp(str1, str2);
printf("Comparison result: %d\n", result);
// strchr()
char *ptr = strchr(str1, 'l’);
printf("First occurrence of 'l': %s\n", ptr);
// strrchr()
ptr = strrchr(str1, 'l’);
printf("Last occurrence of 'l': %s\n", ptr);
// strstr()
ptr = strstr(str1, "ll");
printf("First occurrence of 'll': %s\n", ptr);
return 0;
}
• OUTPUT
Length of str1: 5
Copied string: Hello
Concatenated string: HelloWorld
Comparison result: -1
First occurrence of 'l': llo
Last occurrence of 'l': lo
First occurrence of 'll': llo
ADVANTAGE
ADVANTAGES AND DISADVANTAGES
ADVANTAGES DISADVANTAGES
1. Efficient Memory Use: String handling 1. Efficient Memory Use: String handling
functions in C allow for efficient memory functions in C allow for efficient memory
use by only allocating memory for the string use by only allocating memory for the string
when it is needed. when it is needed.
2. Flexibility: C string handling functions 2. Flexibility: C string handling functions
provide a range of functions for provide a range of functions for
manipulating strings, including manipulating strings, including
concatenation, comparison, and searching. concatenation, comparison, and searching.
3. Portability: C string handling functions 3. Portability: C string handling functions are
are widely supported and can be used on a widely supported and can be used on a
variety of platforms. variety of platforms.
4. Low-Level Memory Management: C 4. Low-Level Memory Management: C string
string handling functions provide low-level handling functions provide low-level
memory management, which can be useful memory management, which can be useful
for optimizing memory usage in certain for optimizing memory usage in certain
applications. applications.
5. Fast Execution: C string handling 5. Fast Execution: C string handling
functions are typically fast and efficient, functions are typically fast and efficient,
making them suitable for applications making them suitable for applications
where performance is critical.# where performance is critical.#
CONCLUSION
C string handling functions are a crucial part of the C
programming language, providing a range of functions for
manipulating and processing strings. These functions are
essential for many applications, including text processing, data
validation, and user input handling. While C string handling
functions can be error-prone and vulnerable to security risks if
not used correctly, following best practices such as bounds
checking, using safe functions, validating input, and utilizing
Unicode support can help developers write efficient, secure, and
reliable code. By mastering C string handling functions,
developers can create robust and effective applications that meet
the needs of their users.
REFERENCE
[Link]
[Link] C Programming Language- Brian [Link] & Dennis [Link]
➢ [Link]
➢[Link]
➢[Link] does-the-
linker-actually-do-when-linking-a-pointer variable-to-an-array-in