SlideShare a Scribd company logo
SARVAJANIK COLLEGE OF
ENGINEERING AND TECHNOLOGY
Branch : Textile technology (FY)
Subject: Computer Programming Utilities
Topic: String
Developed by:
gujarat technological
university
• Romil Deyora (07)
• Jenith Dudhwala (09)
• Jay Ghinaiya (10)
• Viren Gohil (11)
• Sarthak Gujarati (12)
• Avi Patel(23)
String:
• A String is an array of characters stored in consecutive
memory location.
• In string , the ending character is always the null character
‘0’. The null character acts as a String terminator.
How to input string ?
• Scanf function can be use to take string input, the problem with scanf function
is it terminate first space character. And, hence we will use gets () to take
input.
For ex. gets(string variable name)
How to print string value ?
• Puts() is use to print string value.
For ex. Puts(string variable name)
• Use %s field specification in scanf to read string
– ignores leading white space
– reads characters until next white space encountered
– C stores null (0) char after last non-white space char
– Reads into array (no & before name, array is a pointer)
• Example:
char Name[11];
scanf(“%s”,Name);
Character Strings
 A sequence of characters is often referred to as a character “string”.
 A string is stored in an array of type char ending with the null character '0 '.
DISTINCTION BETWEEN CHARACTERS AND
STRINGS
• The representation of a char (e.g., ‘Q’) and a string (e.g., “Q”) is
essentially different.
• A string is an array of characters ended with the null character.
Q
Character ‘Q’
Q 0
String “Q”
getline
 The function getline can be used to read an entire line of input into a
string variable.
 The getline function has three parameters:
 The first specifies the area into which the string is to be read.
 The second specifies the maximum number of characters, including the
string delimiter.
 The third specifies an optional terminating character. If not included,
getline stops at ‘n’.
String functions:
Below are the few standard string-handling library functions that deal with
strings. They all are declared in the header file ‘string.h’.
STRING LENGTH
Syntax: int strlen(char *str)
returns the length (integer) of the string argument
counts the number of characters until an 0 encountered
does not count 0 char
Example:
char str1 = “hello”;
strlen(str1) would return 5
COPYING A STRING
Syntax:
char *strcpy(char *dst, char *src)
copies the characters (including the 0) from the source string (src) to the destination string (dst)
dst should have enough space to receive entire string (if not, other data may get written over)
if the two strings overlap (e.g., copying a string onto itself) the results are unpredictable
return value is the destination string (dst)
char *strncpy(char *dst, char *src, int n)
similar to strcpy, but the copy stops after n characters
if n non-null (not 0) characters are copied, then no 0 is copied
STRING COMPARISON
Syntax:
int strcmp(char *str1, char *str2)
compares str1 to str2, returns a value based on the first character they differ at:
less than 0
if ASCII value of the character they differ at is smaller for str1
or if str1 starts the same as str2 (and str2 is longer)
greater than 0
if ASCII value of the character they differ at is larger for str1
or if str2 starts the same as str1 (and str1 is longer)
0 if the two strings do not differ
STRING CONCATENATION
Syntax:
char *strcat(char *dstS, char *addS)
appends the string at addS to the string dstS (after dstS’s delimiter)
returns the string dstS
can cause problems if the resulting string is too long to fit in dstS
char *strncat(char *dstS, char *addS, int n)
appends the first n characters of addS to dstS
if less than n characters in addS only the characters in addS appended
always appends a 0 character
• Strrev():
-This function is use to reverse the given input string.
• Strlwr():
-This​ function is use to convert the string
lower case.
• Strupr():
-This​ function is use to convert the string into
upper case.
#include<stdio.h>
#include<string.h>
Example:
main()
{
int a,b;
char s1[100],s2[100];
printf("Enter a string.n");
scanf("%s",s1);
//write a program to print
strlen(),strrev(),strcat(),strcpy(),strupr(),strlwr(),strcmp()//
printf("Enter the operation you wish to perform on the string:n1. String
Lengthn2. String Reversen3. String Concatenationn4. String Copyn5. String
Upper Casen6. String Lower Casen7. String Comparisonn");
scanf("%d",&a);
switch(a)
{
case 1:
{
b=strlen(s1);
printf("String Length = %d",b);
break;
}
case 2:
{
printf("String Reverse = %s",strrev(s1));
break;
}
case 3:
{
printf("Enter the target string.n");
scanf("%s",s2);
strcat(s2,s1);
printf("Result - %s",s2);
break;
}
case 4:
{
strcpy(s2,s1);
printf("Copied String - %s",s2);
break;
}
case 5:
{
printf("The Upper Case of String is %s",strupr(s1));
break;
}
case 6:
{
printf("The Lower Case of String is %s",strlwr(s1));
break;
}
case 7:
{
printf("Enter the string you wish to compare with the
previous string.n");
scanf("%s",s2);
a=strcmp(s1,s2);
printf("String Compare %d",a);
break;
}
default:
{
printf("You have not entered a valid option.");
}
}
}
Computer Programming Utilities the subject of BE first year students, and this power point presentation topic is String.

More Related Content

PPT
Operation on string presentation
PPTX
Implementation Of String Functions In C
PPTX
Strings in C
PPTX
Managing I/O & String function in C
PPTX
String in c programming
PPTX
PPT
Strings
Operation on string presentation
Implementation Of String Functions In C
Strings in C
Managing I/O & String function in C
String in c programming
Strings

What's hot (20)

PDF
PPTX
C programming - String
PDF
Character Array and String
PPT
Strings Functions in C Programming
PDF
String.ppt
PDF
Strings in c language
PPTX
Introduction to c programming
PPTX
Handling of character strings C programming
PPT
PPTX
String in programming language in c or c++
PPTX
Computer programming 2 Lesson 12
PDF
05 c++-strings
PPT
Strings
DOC
String in c
PPT
Strings v.1.1
PPTX
Strings in c++
PDF
Strings IN C
PPTX
Strings
C programming - String
Character Array and String
Strings Functions in C Programming
String.ppt
Strings in c language
Introduction to c programming
Handling of character strings C programming
String in programming language in c or c++
Computer programming 2 Lesson 12
05 c++-strings
Strings
String in c
Strings v.1.1
Strings in c++
Strings IN C
Strings
Ad

Similar to Computer Programming Utilities the subject of BE first year students, and this power point presentation topic is String. (20)

PPT
THE FORMAT AND USAGE OF STRINGS IN C.PPT
PPT
Chapterabcdefghijklmnopqrdstuvwxydanniipo
PPT
Cfbcgdhfghdfhghggfhghghgfhgfhgfhhapter11.PPT
PDF
String notes
PDF
0-Slot21-22-Strings.pdf
PDF
STRINGS IN C MRS.SOWMYA JYOTHI.pdf
PDF
Chapter 4 (Part II) - Array and Strings.pdf
PDF
Strings in c mrs.sowmya jyothi
PDF
Strings-Computer programming
PDF
Strings part2
PPTX
unit-5 String Math Date Time AI presentation
PDF
9 character string &amp; string library
PDF
Python data handling
PPTX
introduction to strings in c programming
PPT
Strings in c
PPTX
UNIT 4C-Strings.pptx for c language and basic knowledge
PDF
[ITP - Lecture 17] Strings in C/C++
PPTX
Strings cprogramminglanguagedsasheet.pptx
PPTX
Lecture 15_Strings and Dynamic Memory Allocation.pptx
THE FORMAT AND USAGE OF STRINGS IN C.PPT
Chapterabcdefghijklmnopqrdstuvwxydanniipo
Cfbcgdhfghdfhghggfhghghgfhgfhgfhhapter11.PPT
String notes
0-Slot21-22-Strings.pdf
STRINGS IN C MRS.SOWMYA JYOTHI.pdf
Chapter 4 (Part II) - Array and Strings.pdf
Strings in c mrs.sowmya jyothi
Strings-Computer programming
Strings part2
unit-5 String Math Date Time AI presentation
9 character string &amp; string library
Python data handling
introduction to strings in c programming
Strings in c
UNIT 4C-Strings.pptx for c language and basic knowledge
[ITP - Lecture 17] Strings in C/C++
Strings cprogramminglanguagedsasheet.pptx
Lecture 15_Strings and Dynamic Memory Allocation.pptx
Ad

Recently uploaded (20)

PPTX
school management -TNTEU- B.Ed., Semester II Unit 1.pptx
PDF
3rd Neelam Sanjeevareddy Memorial Lecture.pdf
PDF
Saundersa Comprehensive Review for the NCLEX-RN Examination.pdf
PDF
Black Hat USA 2025 - Micro ICS Summit - ICS/OT Threat Landscape
PDF
O5-L3 Freight Transport Ops (International) V1.pdf
PDF
Chapter 2 Heredity, Prenatal Development, and Birth.pdf
PPTX
GDM (1) (1).pptx small presentation for students
PPTX
PPT- ENG7_QUARTER1_LESSON1_WEEK1. IMAGERY -DESCRIPTIONS pptx.pptx
PDF
Anesthesia in Laparoscopic Surgery in India
PDF
Microbial disease of the cardiovascular and lymphatic systems
PDF
The Lost Whites of Pakistan by Jahanzaib Mughal.pdf
PPTX
Cell Types and Its function , kingdom of life
PPTX
Introduction_to_Human_Anatomy_and_Physiology_for_B.Pharm.pptx
PDF
TR - Agricultural Crops Production NC III.pdf
PDF
Computing-Curriculum for Schools in Ghana
PDF
Insiders guide to clinical Medicine.pdf
PDF
grade 11-chemistry_fetena_net_5883.pdf teacher guide for all student
PPTX
PPH.pptx obstetrics and gynecology in nursing
PDF
RMMM.pdf make it easy to upload and study
PDF
FourierSeries-QuestionsWithAnswers(Part-A).pdf
school management -TNTEU- B.Ed., Semester II Unit 1.pptx
3rd Neelam Sanjeevareddy Memorial Lecture.pdf
Saundersa Comprehensive Review for the NCLEX-RN Examination.pdf
Black Hat USA 2025 - Micro ICS Summit - ICS/OT Threat Landscape
O5-L3 Freight Transport Ops (International) V1.pdf
Chapter 2 Heredity, Prenatal Development, and Birth.pdf
GDM (1) (1).pptx small presentation for students
PPT- ENG7_QUARTER1_LESSON1_WEEK1. IMAGERY -DESCRIPTIONS pptx.pptx
Anesthesia in Laparoscopic Surgery in India
Microbial disease of the cardiovascular and lymphatic systems
The Lost Whites of Pakistan by Jahanzaib Mughal.pdf
Cell Types and Its function , kingdom of life
Introduction_to_Human_Anatomy_and_Physiology_for_B.Pharm.pptx
TR - Agricultural Crops Production NC III.pdf
Computing-Curriculum for Schools in Ghana
Insiders guide to clinical Medicine.pdf
grade 11-chemistry_fetena_net_5883.pdf teacher guide for all student
PPH.pptx obstetrics and gynecology in nursing
RMMM.pdf make it easy to upload and study
FourierSeries-QuestionsWithAnswers(Part-A).pdf

Computer Programming Utilities the subject of BE first year students, and this power point presentation topic is String.

  • 1. SARVAJANIK COLLEGE OF ENGINEERING AND TECHNOLOGY Branch : Textile technology (FY) Subject: Computer Programming Utilities Topic: String Developed by: gujarat technological university • Romil Deyora (07) • Jenith Dudhwala (09) • Jay Ghinaiya (10) • Viren Gohil (11) • Sarthak Gujarati (12) • Avi Patel(23)
  • 2. String: • A String is an array of characters stored in consecutive memory location. • In string , the ending character is always the null character ‘0’. The null character acts as a String terminator.
  • 3. How to input string ? • Scanf function can be use to take string input, the problem with scanf function is it terminate first space character. And, hence we will use gets () to take input. For ex. gets(string variable name) How to print string value ? • Puts() is use to print string value. For ex. Puts(string variable name)
  • 4. • Use %s field specification in scanf to read string – ignores leading white space – reads characters until next white space encountered – C stores null (0) char after last non-white space char – Reads into array (no & before name, array is a pointer) • Example: char Name[11]; scanf(“%s”,Name);
  • 5. Character Strings  A sequence of characters is often referred to as a character “string”.  A string is stored in an array of type char ending with the null character '0 '.
  • 6. DISTINCTION BETWEEN CHARACTERS AND STRINGS • The representation of a char (e.g., ‘Q’) and a string (e.g., “Q”) is essentially different. • A string is an array of characters ended with the null character. Q Character ‘Q’ Q 0 String “Q”
  • 7. getline  The function getline can be used to read an entire line of input into a string variable.  The getline function has three parameters:  The first specifies the area into which the string is to be read.  The second specifies the maximum number of characters, including the string delimiter.  The third specifies an optional terminating character. If not included, getline stops at ‘n’.
  • 8. String functions: Below are the few standard string-handling library functions that deal with strings. They all are declared in the header file ‘string.h’.
  • 9. STRING LENGTH Syntax: int strlen(char *str) returns the length (integer) of the string argument counts the number of characters until an 0 encountered does not count 0 char Example: char str1 = “hello”; strlen(str1) would return 5
  • 10. COPYING A STRING Syntax: char *strcpy(char *dst, char *src) copies the characters (including the 0) from the source string (src) to the destination string (dst) dst should have enough space to receive entire string (if not, other data may get written over) if the two strings overlap (e.g., copying a string onto itself) the results are unpredictable return value is the destination string (dst) char *strncpy(char *dst, char *src, int n) similar to strcpy, but the copy stops after n characters if n non-null (not 0) characters are copied, then no 0 is copied
  • 11. STRING COMPARISON Syntax: int strcmp(char *str1, char *str2) compares str1 to str2, returns a value based on the first character they differ at: less than 0 if ASCII value of the character they differ at is smaller for str1 or if str1 starts the same as str2 (and str2 is longer) greater than 0 if ASCII value of the character they differ at is larger for str1 or if str2 starts the same as str1 (and str1 is longer) 0 if the two strings do not differ
  • 12. STRING CONCATENATION Syntax: char *strcat(char *dstS, char *addS) appends the string at addS to the string dstS (after dstS’s delimiter) returns the string dstS can cause problems if the resulting string is too long to fit in dstS char *strncat(char *dstS, char *addS, int n) appends the first n characters of addS to dstS if less than n characters in addS only the characters in addS appended always appends a 0 character
  • 13. • Strrev(): -This function is use to reverse the given input string. • Strlwr(): -This​ function is use to convert the string lower case. • Strupr(): -This​ function is use to convert the string into upper case.
  • 14. #include<stdio.h> #include<string.h> Example: main() { int a,b; char s1[100],s2[100]; printf("Enter a string.n"); scanf("%s",s1); //write a program to print strlen(),strrev(),strcat(),strcpy(),strupr(),strlwr(),strcmp()// printf("Enter the operation you wish to perform on the string:n1. String Lengthn2. String Reversen3. String Concatenationn4. String Copyn5. String Upper Casen6. String Lower Casen7. String Comparisonn"); scanf("%d",&a);
  • 15. switch(a) { case 1: { b=strlen(s1); printf("String Length = %d",b); break; } case 2: { printf("String Reverse = %s",strrev(s1)); break; } case 3: { printf("Enter the target string.n"); scanf("%s",s2); strcat(s2,s1); printf("Result - %s",s2); break; }
  • 16. case 4: { strcpy(s2,s1); printf("Copied String - %s",s2); break; } case 5: { printf("The Upper Case of String is %s",strupr(s1)); break; } case 6: { printf("The Lower Case of String is %s",strlwr(s1)); break; }
  • 17. case 7: { printf("Enter the string you wish to compare with the previous string.n"); scanf("%s",s2); a=strcmp(s1,s2); printf("String Compare %d",a); break; } default: { printf("You have not entered a valid option."); } } }