STRING OPERATIONS
Project submitted to the
SRM University – AP, Andhra Pradesh
for the partial fulfillment of the requirements to award the degree of
Bachelor of Technology/Master of Technology
In
Computer Science and Engineering
School of Engineering and Sciences
Submitted by
Candidate Name
AP22110011294 KATURI SAM SANTOSH
AP22110011295 MALLADI SUJAN JASWANTH SARMA
AP22110011296 KALATHOTI ABHI ROHIT
AP22110011297 THUNUGUNTLA MARUTHI SAI SASANK
AP22110011298 BAHADURSHA KOWSHIK SREE
Under the Guidance of
Dr Aurobindo Behera
CSE Dept
SRM University–AP
Neerukonda, Mangalagiri, Guntur
Andhra Pradesh – 522 240
[January,2023]
1
Index
1. Acknowledgements 3
2. Abstract 3
3. Code 4-8
4. Explanation 9 - 10
5. Inputs and Outputs 10 - 12
5. Conclusions 12
[Link] 12
2
Acknowledgements
We would like to express our gratitude to Dr Aurobindo Behera for assisting us
with the research at every step. Without the advice and assistance of our
adviser, this study effort would not be feasible. Your useful advice and
suggestions were really helpful to us during the project’s completion. In
this aspect, we are eternally grateful to you. I would like to acknowledge
that this project was completed entirely by us and not by someone else.
Abstract
Through this project we expressed our view about the way we understood
about the predefined functions of strings. Our project may be a reference
for the beginners to code the predefined library sting functions. It is easy
to concatenate two strings, compare two strings, copying two strings,
finding length of the string, reversing a given string, converting lower case
letters of string into uppercase letters, converting uppercase letters into
lowercase letters by using predefined but we did the above-mentioned
tasks without using predefined library functions.
Now its compilers job to give out
Name of the function
Strings that are required as per the function
3
CODE
#include <stdio.h>
int main ()
{
int choice, i, j;
char str1[200], str2[200];
printf ("Enter a string: ");
scanf("%[^\n]s",&str1);
printf("\n ----------Choose an operation:\n");
printf("\t '1' for Concatenation of string\n");
printf("\t '2' for Compare the string\n");
printf("\t '3' for Copy the string\n");
printf("\t '4' for Finding length\n");
printf("\t '5' for Reverse of the string\n");
printf("\t '6' for coversion to UPPERCASE letters of string\n");
printf("\t '7' for conversion to lowercase letters of string\n");
scanf("%d", &choice);
switch(choice) {
case 1:
printf("Enter another string to concatenate: ");
scanf("%s",&str2);
for (i = 0; str1[i] != '\0'; i++) {
}
4
for (j = 0; str2[j] != '\0'; j++)
{
str1[i] = str2[j];
i++;
}
str1[i] = '\0';
printf("Concatenated string: %s\n", str1);
break;
case 2:
printf("Enter another string to compare: ");
scanf("%s",&str2);
i = 0;
while (str1[i] == str2[i] && str1[i] != '\0')
{
i++;
}
if (str1[i] == str2[i]) {
printf("Strings are equal\n");
} else {
printf("Strings are not equal\n");
}
break;
case 3:
for (i = 0; str1[i] != '\0'; i++) {
str2[i] = str1[i];
}
str2[i] = '\0';
5
printf("Copied string: %s\n", str2);
break;
case 4:
i = 0;
while (str1[i] != '\0') {
i++;
}
printf("Length of string: %d\n", i);
break;
case 5:
i = 0;
j = 0;
while (str1[i] != '\0') {
i++;
}
i--;
while (i >= 0) {
str2[j] = str1[i];
i--;
j++;
}
str2[j] = '\0';
printf("Reversed string: %s\n", str2);
break;
6
case 6:
for (i = 0; str1[i]!='\0'; i++)
{
if(str1[i] >= 'a' && str1[i] <= 'z')
{
str1[i] = str1[i] -32;
}
}
printf("\n The given String in Upper Case = %s", str1);
break;
case 7:
for (i = 0; str1[i]!='\0'; i++)
{
if(str1[i] >= 'A' && str1[i] <= 'Z')
{
str1[i] = str1[i] + 32;
}
}
printf("\n The given String in Lower Case = %s", str1);
break;
default:
printf("Invalid choice\n");
}
return 0;
}
7
8
Explanation
We described codes of 7 different predefined string functions.
We used 7 cases to make the project: -
Case 1: Concatenation of two Strings in this case first
the user should enter a string and then some statements
will get printed and enter digit ‘1’ for executing
concatenation, now the user will be asked to enter another
string to concatentate and user should enter the other
string to concatentate and the required output of
concatenation of the strings gets printed.
Case 2: Comparing two strings in this case first the
user should enter a string and then some statements will
get printed and enter digit ‘2’ for executing the comparing
functions, now the user will be asked to enter another
string to compare and user should enter the other string
to compare and it displays whether the strings are equal
or not.
Case 3: Copying a string in this case first the user
should enter a string and then some statements will get
printed and enter digit ‘3’ for executing the copying
functions, now in the output it displays the copied string.
Case 4: Finding the length of the string in this case
first the user should enter a string and then some
statements will get printed and enter digit ‘4’ for finding
the length of the string, now in the output it displays the
length of the string.
Case 5: Finding the reverse of the string in this case
first the user should enter a string and then some
statements will get printed and enter digit ‘5’ for finding
the reverse of the string, now in the output it prints the
reverse string of the entered string.
Case 6: Conversion of Lowercase letters of a string
into Upper case letters in this case first the user should
enter a string and then some statements will get printed
and enter digit ‘6’ for converting the lowercase letters of
the string into uppercase letters, now in the output it
prints the string containing all uppercase letters.
9
Case 7: Conversion of Uppercase letters of a string
into Lowercase letters in this case first the user should
enter a string and then some statements will get printed
and enter digit ‘7’ for converting the uppercase letters of
the string into lowercase letters, now in the output it prints
the string containing all lowercase letters.
Input and Output
For Example :
Input:
String 1: “Computer”
1
String 2: “Science”
Output:
Enter a string: Computer
----------Choose an operation:
'1' for Concatenation of string
'2' for Compare the string
'3' for Copy the string
'4' for Finding length
'5' for Reverse of the string
'6' for coversion to UPPERCASE letters of string
'7' for conversion to lowercase letters of string
1
Enter another string to concatenate: Science
Concatenated string: ComputerScience
10
Conclusions
The String operations are widely used throughout the world and
many of the learners don’t know how the code for those
functions were written. We had written codes for 7 different
string functions. And these codes are very easy to understand.
We can use other two ways to code this project like by using
functions and file inclusions but while we are coding we should
reduce the size of the code to save the memory. If we use file
inclusions or functions it may consume more space than using
switch cases. So, to reduce the usage of memory we decided to
code the project using switch cases. From the bottom of our
heart, we thank our CSE lecturer Dr Aurobindo Behera sir for
sharing his knowledge on these string functions and helping us
to make this project.
References
The book “C Programming Language” written by Dennis
Ritchie.
The book “C Programming: A Modern Approach” written
by K. N. King.
The book “The C Programming Language” written by Brian
W. Kernighan and Dennis M. Ritchie.
11