SlideShare a Scribd company logo
1 of 18
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

What's hot

What's hot (20)

Strings
StringsStrings
Strings
 
C programming - String
C programming - StringC programming - String
C programming - String
 
Character Array and String
Character Array and StringCharacter Array and String
Character Array and String
 
Strings Functions in C Programming
Strings Functions in C ProgrammingStrings Functions in C Programming
Strings Functions in C Programming
 
String.ppt
String.pptString.ppt
String.ppt
 
Strings in c language
Strings in  c languageStrings in  c language
Strings in c language
 
Introduction to c programming
Introduction to c programmingIntroduction to c programming
Introduction to c programming
 
Handling of character strings C programming
Handling of character strings C programmingHandling of character strings C programming
Handling of character strings C programming
 
String c
String cString c
String c
 
String in programming language in c or c++
 String in programming language  in c or c++  String in programming language  in c or c++
String in programming language in c or c++
 
string in C
string in Cstring in C
string in C
 
Computer programming 2 Lesson 12
Computer programming 2  Lesson 12Computer programming 2  Lesson 12
Computer programming 2 Lesson 12
 
05 c++-strings
05 c++-strings05 c++-strings
05 c++-strings
 
Strings
StringsStrings
Strings
 
String in c
String in cString in c
String in c
 
Strings v.1.1
Strings v.1.1Strings v.1.1
Strings v.1.1
 
Strings in c++
Strings in c++Strings in c++
Strings in c++
 
Strings IN C
Strings IN CStrings IN C
Strings IN C
 
Strings
StringsStrings
Strings
 
Chap 8(strings)
Chap 8(strings)Chap 8(strings)
Chap 8(strings)
 

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

Lecture 15_Strings and Dynamic Memory Allocation.pptx
Lecture 15_Strings and  Dynamic Memory Allocation.pptxLecture 15_Strings and  Dynamic Memory Allocation.pptx
Lecture 15_Strings and Dynamic Memory Allocation.pptx
JawadTanvir
 

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

String notes
String notesString notes
String notes
 
0-Slot21-22-Strings.pdf
0-Slot21-22-Strings.pdf0-Slot21-22-Strings.pdf
0-Slot21-22-Strings.pdf
 
STRINGS IN C MRS.SOWMYA JYOTHI.pdf
STRINGS IN C MRS.SOWMYA JYOTHI.pdfSTRINGS IN C MRS.SOWMYA JYOTHI.pdf
STRINGS IN C MRS.SOWMYA JYOTHI.pdf
 
Chapter 4 (Part II) - Array and Strings.pdf
Chapter 4 (Part II) - Array and Strings.pdfChapter 4 (Part II) - Array and Strings.pdf
Chapter 4 (Part II) - Array and Strings.pdf
 
Strings in c mrs.sowmya jyothi
Strings in c mrs.sowmya jyothiStrings in c mrs.sowmya jyothi
Strings in c mrs.sowmya jyothi
 
Strings in c++
Strings in c++Strings in c++
Strings in c++
 
Strings-Computer programming
Strings-Computer programmingStrings-Computer programming
Strings-Computer programming
 
Strings part2
Strings part2Strings part2
Strings part2
 
9 character string &amp; string library
9  character string &amp; string library9  character string &amp; string library
9 character string &amp; string library
 
Python data handling
Python data handlingPython data handling
Python data handling
 
introduction to strings in c programming
introduction to strings in c programmingintroduction to strings in c programming
introduction to strings in c programming
 
Strings in c
Strings in cStrings in c
Strings in c
 
[ITP - Lecture 17] Strings in C/C++
[ITP - Lecture 17] Strings in C/C++[ITP - Lecture 17] Strings in C/C++
[ITP - Lecture 17] Strings in C/C++
 
Lecture 15_Strings and Dynamic Memory Allocation.pptx
Lecture 15_Strings and  Dynamic Memory Allocation.pptxLecture 15_Strings and  Dynamic Memory Allocation.pptx
Lecture 15_Strings and Dynamic Memory Allocation.pptx
 
Unitii string
Unitii stringUnitii string
Unitii string
 
Character Arrays and strings in c language
Character Arrays and strings in c languageCharacter Arrays and strings in c language
Character Arrays and strings in c language
 
Ch09
Ch09Ch09
Ch09
 
Team 1
Team 1Team 1
Team 1
 
Lecture 05 2017
Lecture 05 2017Lecture 05 2017
Lecture 05 2017
 
C q 3
C q 3C q 3
C q 3
 

Recently uploaded

Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...
Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...
Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...
EADTU
 
SURVEY I created for uni project research
SURVEY I created for uni project researchSURVEY I created for uni project research
SURVEY I created for uni project research
CaitlinCummins3
 

Recently uploaded (20)

How to Manage Website in Odoo 17 Studio App.pptx
How to Manage Website in Odoo 17 Studio App.pptxHow to Manage Website in Odoo 17 Studio App.pptx
How to Manage Website in Odoo 17 Studio App.pptx
 
Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...
Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...
Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...
 
BỘ LUYỆN NGHE TIẾNG ANH 8 GLOBAL SUCCESS CẢ NĂM (GỒM 12 UNITS, MỖI UNIT GỒM 3...
BỘ LUYỆN NGHE TIẾNG ANH 8 GLOBAL SUCCESS CẢ NĂM (GỒM 12 UNITS, MỖI UNIT GỒM 3...BỘ LUYỆN NGHE TIẾNG ANH 8 GLOBAL SUCCESS CẢ NĂM (GỒM 12 UNITS, MỖI UNIT GỒM 3...
BỘ LUYỆN NGHE TIẾNG ANH 8 GLOBAL SUCCESS CẢ NĂM (GỒM 12 UNITS, MỖI UNIT GỒM 3...
 
Mattingly "AI and Prompt Design: LLMs with NER"
Mattingly "AI and Prompt Design: LLMs with NER"Mattingly "AI and Prompt Design: LLMs with NER"
Mattingly "AI and Prompt Design: LLMs with NER"
 
Supporting Newcomer Multilingual Learners
Supporting Newcomer  Multilingual LearnersSupporting Newcomer  Multilingual Learners
Supporting Newcomer Multilingual Learners
 
TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...
TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...
TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...
 
8 Tips for Effective Working Capital Management
8 Tips for Effective Working Capital Management8 Tips for Effective Working Capital Management
8 Tips for Effective Working Capital Management
 
SURVEY I created for uni project research
SURVEY I created for uni project researchSURVEY I created for uni project research
SURVEY I created for uni project research
 
Major project report on Tata Motors and its marketing strategies
Major project report on Tata Motors and its marketing strategiesMajor project report on Tata Motors and its marketing strategies
Major project report on Tata Motors and its marketing strategies
 
Andreas Schleicher presents at the launch of What does child empowerment mean...
Andreas Schleicher presents at the launch of What does child empowerment mean...Andreas Schleicher presents at the launch of What does child empowerment mean...
Andreas Schleicher presents at the launch of What does child empowerment mean...
 
demyelinated disorder: multiple sclerosis.pptx
demyelinated disorder: multiple sclerosis.pptxdemyelinated disorder: multiple sclerosis.pptx
demyelinated disorder: multiple sclerosis.pptx
 
ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH FORM 50 CÂU TRẮC NGHI...
ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH FORM 50 CÂU TRẮC NGHI...ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH FORM 50 CÂU TRẮC NGHI...
ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH FORM 50 CÂU TRẮC NGHI...
 
Analyzing and resolving a communication crisis in Dhaka textiles LTD.pptx
Analyzing and resolving a communication crisis in Dhaka textiles LTD.pptxAnalyzing and resolving a communication crisis in Dhaka textiles LTD.pptx
Analyzing and resolving a communication crisis in Dhaka textiles LTD.pptx
 
Trauma-Informed Leadership - Five Practical Principles
Trauma-Informed Leadership - Five Practical PrinciplesTrauma-Informed Leadership - Five Practical Principles
Trauma-Informed Leadership - Five Practical Principles
 
OS-operating systems- ch05 (CPU Scheduling) ...
OS-operating systems- ch05 (CPU Scheduling) ...OS-operating systems- ch05 (CPU Scheduling) ...
OS-operating systems- ch05 (CPU Scheduling) ...
 
How To Create Editable Tree View in Odoo 17
How To Create Editable Tree View in Odoo 17How To Create Editable Tree View in Odoo 17
How To Create Editable Tree View in Odoo 17
 
diagnosting testing bsc 2nd sem.pptx....
diagnosting testing bsc 2nd sem.pptx....diagnosting testing bsc 2nd sem.pptx....
diagnosting testing bsc 2nd sem.pptx....
 
e-Sealing at EADTU by Kamakshi Rajagopal
e-Sealing at EADTU by Kamakshi Rajagopale-Sealing at EADTU by Kamakshi Rajagopal
e-Sealing at EADTU by Kamakshi Rajagopal
 
PSYPACT- Practicing Over State Lines May 2024.pptx
PSYPACT- Practicing Over State Lines May 2024.pptxPSYPACT- Practicing Over State Lines May 2024.pptx
PSYPACT- Practicing Over State Lines May 2024.pptx
 
OSCM Unit 2_Operations Processes & Systems
OSCM Unit 2_Operations Processes & SystemsOSCM Unit 2_Operations Processes & Systems
OSCM Unit 2_Operations Processes & Systems
 

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."); } } }