SlideShare a Scribd company logo
SARANYA K
AP/CSE
SRIT
 The string is actually a one-dimensional array of characters
which is terminated by a null character '0'.
 All the string handling functions are prototyped in: string.h
header file. So while using any string related function, don't
forget to include string.h.
 String constants have double quote marks around them.
 String constants can be assigned to a char array either with
no size specified, or the size can also be specified, but don't
forget to leave a space for the null character.
 Strings are often needed to be manipulated by the programmer
according to the need of a problem. Hence, C provides a
variety of string handling functions.
 String handling functions refers to a group of functions
implementing various operations on strings.
 Some of the operations performed by the string handling
functions includes:
› Length (number of characters in the string).
› Concatenation (adding two are more strings)
› Comparing two strings.
› Substring (Extract substring from a given string)
› Copy(copies one string over another)
 The various string handling functions supported by C are as
follows:
 strlen()
It is used to find the length of the string.
syntax:
strlen(string)
 strcpy()
It is used to copy one string to another.
syntax:
strcpy(string1,string2)
 strcat()
It is used to combine two strings.
syntax:
strcat(string1,string2)
 strcmp()
It is used to compare two strings.
syntax:
strcmp(string1,string2)
 Returns 0 if two strings are equal.
 Return value <0 if s1 is less than s2.
 Return value >0 if s1 is greater than s2.
 strrev()
It used to reverse a string.
syntax:
strrev(string)
 strlwr(), strupr()
It used to change the case of a string.
syntax:
strlwr(string)
strupr(string)
 strncpy()
It used to copy ‘n’ characters of one string to another.
 strstr()
It is used to determine the first occurrence of a
given string in another string.
 strncat()
It appends source string to destination string up to
specified length.
 strspn()
It is used to find up to what length two strings are
identical.
 strncmp()
It is used to compare ‘n’ character of two strings.
 strcmpi()
It is used to compare two strings without regarding the case.
 strnicmp()
It is used to compare first ‘n’ characters of two strings
without regarding the case.
 strchr()
It is used to determine the first occurrence of a given
character in a string.
 strrchr()
It is used to determine the last occurrence of a given
character in a string.
#include<stdio.h>
#include<conio.h>
#include<string.h>
void main()
{
char a[]="college";
int b;
clrscr();
b=strlen(a);
printf("nThe length of the string is %d",b);
getch();
}
Output:
The length of the string is 7
#include<stdio.h>
#include<conio.h>
#include<string.h>
void main()
{
char a[ ]="IT";
char b[ ]="Dept";
clrscr();
strcpy(a,b);
printf("nThe string is %s",a);
getch();
}
Output:
The string is Dept
#include<stdio.h>
#include<conio.h>
#include<string.h>
void main()
{
char a[ ]="IT";
char b[ ]="Dept";
clrscr();
strcat(a,b);
printf("nThe string is %s",a);
getch();
}
Output:
The string is ITDept
#include<stdio.h>
#include<conio.h>
#include<string.h>
void main()
{
char a[ ]="itdept";
char b[ ]="it";
int i;
clrscr();
i=strcmp(a,b);
if(i==0)
printf("nstrings are equal:%d",i);
else if(i<0)
printf("nstring1 is less than string2:%d",i);
else
printf("nstring1 is greater than string2:%d",i);
getch();
}
Output:
string1 is greater than string2:100
#include<stdio.h>
#include<conio.h>
#include<string.h>
void main()
{
char a[ ]="itdept";
clrscr();
printf("nThe string is :%s",a);
strupr(a);
printf("nThe string after conversion to uppercase :%s",a);
strlwr(a);
printf("nThe string after conversion to lowercase :%s",a);
getch();
}
The string is : itdept
The string after conversion to uppercase :ITDEPT
The string after conversion to lowercase : itdept
#include<stdio.h>
#include<conio.h>
#include<string.h>
void main()
{
char a[ ]="Dept";
clrscr();
printf("nThe string is %s",strrev(a));
getch();
}
Output:
The string is tpeD
#include<stdio.h>
#include<conio.h>
#include<string.h>
void main()
{
char a[ ]="itdept";
char b[15];
int i=0;
clrscr();
strncpy(b,a,2);
b[2]='0';
printf("nThe string is :%s",b);
getch();
}
Output:
The string is :it
#include<stdio.h>
#include<conio.h>
#include<string.h>
void main()
{
int len,i,j;
char str[15];
clrscr();
printf("n Enter the string:");
scanf("%s",str);
len=strlen(str);
for(i=0,j=len-1;i<len/2;i++,j--)
{
if(str[i]!=str[j])
{
printf("n The String is not a palindrome");
getch();
exit(0);
}
}
printf("n The String is a palindrome");
getch();
}
Output:
Enter the string: abcba
The String is a palindrome

More Related Content

PPTX
Introduction to c programming
PPTX
Managing I/O & String function in C
PPTX
C Programming Unit-3
PPT
Functions and pointers_unit_4
PPT
Strings
PPTX
Implementation Of String Functions In C
DOCX
Type header file in c++ and its function
PDF
Strings in c mrs.sowmya jyothi
Introduction to c programming
Managing I/O & String function in C
C Programming Unit-3
Functions and pointers_unit_4
Strings
Implementation Of String Functions In C
Type header file in c++ and its function
Strings in c mrs.sowmya jyothi

What's hot (20)

PPTX
Unit 8. Pointers
PDF
Strings IN C
PPTX
function, storage class and array and strings
PPT
PDF
Strings in c language
PDF
POINTERS IN C MRS.SOWMYA JYOTHI.pdf
DOC
Assignment c programming
PPT
Lecture 17 - Strings
PPT
Lecture 18 - Pointers
PPT
String & its application
PDF
MANAGING INPUT AND OUTPUT OPERATIONS IN C MRS.SOWMYA JYOTHI.pdf
PPT
Lecture 8- Data Input and Output
PPTX
Programming in C (part 2)
PPTX
C programming(part 3)
PPT
14 strings
PDF
C Programming Assignment
PDF
STRINGS IN C MRS.SOWMYA JYOTHI.pdf
PPT
Lecture 6- Intorduction to C Programming
PPTX
C++ theory
Unit 8. Pointers
Strings IN C
function, storage class and array and strings
Strings in c language
POINTERS IN C MRS.SOWMYA JYOTHI.pdf
Assignment c programming
Lecture 17 - Strings
Lecture 18 - Pointers
String & its application
MANAGING INPUT AND OUTPUT OPERATIONS IN C MRS.SOWMYA JYOTHI.pdf
Lecture 8- Data Input and Output
Programming in C (part 2)
C programming(part 3)
14 strings
C Programming Assignment
STRINGS IN C MRS.SOWMYA JYOTHI.pdf
Lecture 6- Intorduction to C Programming
C++ theory
Ad

Similar to Strings (20)

PPTX
programming for problem solving using C-STRINGSc
PDF
Strings part2
PPTX
Strings CPU GTU
PPTX
Slide -231, Math-1151, lecture-15,Chapter, Chapter 2.2,2.3, 5.1,5.2,5.6.pptx
PPTX
CSE 1102 - Lecture_7 - Strings_in_C.pptx
PPTX
STRING FUNCTION - Programming in C.pptx
PPTX
Computer Programming Utilities the subject of BE first year students, and thi...
PPTX
String (Computer programming and utilization)
PPTX
C programming - String
PPT
Strings in c
PPTX
Module-2_Strings concepts in c programming
PPTX
String predefined functions in C programming
PPTX
cprogramming strings.pptx
PPTX
cprogramming strings.pptx
PPTX
Character Arrays and strings in c language
PPTX
Strings cprogramminglanguagedsasheet.pptx
PDF
Principals of Programming in CModule -5.pdfModule-4.pdf
PPT
Strings(2007)
PPTX
String.pptx
programming for problem solving using C-STRINGSc
Strings part2
Strings CPU GTU
Slide -231, Math-1151, lecture-15,Chapter, Chapter 2.2,2.3, 5.1,5.2,5.6.pptx
CSE 1102 - Lecture_7 - Strings_in_C.pptx
STRING FUNCTION - Programming in C.pptx
Computer Programming Utilities the subject of BE first year students, and thi...
String (Computer programming and utilization)
C programming - String
Strings in c
Module-2_Strings concepts in c programming
String predefined functions in C programming
cprogramming strings.pptx
cprogramming strings.pptx
Character Arrays and strings in c language
Strings cprogramminglanguagedsasheet.pptx
Principals of Programming in CModule -5.pdfModule-4.pdf
Strings(2007)
String.pptx
Ad

Recently uploaded (20)

PDF
PRIZ Academy - 9 Windows Thinking Where to Invest Today to Win Tomorrow.pdf
PPTX
Geodesy 1.pptx...............................................
PPTX
UNIT 4 Total Quality Management .pptx
PPTX
OOP with Java - Java Introduction (Basics)
PPTX
M Tech Sem 1 Civil Engineering Environmental Sciences.pptx
PPTX
Construction Project Organization Group 2.pptx
PPTX
IOT PPTs Week 10 Lecture Material.pptx of NPTEL Smart Cities contd
PPTX
Lecture Notes Electrical Wiring System Components
PDF
Mohammad Mahdi Farshadian CV - Prospective PhD Student 2026
PDF
composite construction of structures.pdf
PDF
Digital Logic Computer Design lecture notes
PDF
Embodied AI: Ushering in the Next Era of Intelligent Systems
PPTX
Strings in CPP - Strings in C++ are sequences of characters used to store and...
PPTX
MET 305 2019 SCHEME MODULE 2 COMPLETE.pptx
PPTX
Sustainable Sites - Green Building Construction
PPTX
Infosys Presentation by1.Riyan Bagwan 2.Samadhan Naiknavare 3.Gaurav Shinde 4...
PDF
July 2025 - Top 10 Read Articles in International Journal of Software Enginee...
PPTX
CARTOGRAPHY AND GEOINFORMATION VISUALIZATION chapter1 NPTE (2).pptx
PPTX
bas. eng. economics group 4 presentation 1.pptx
PPT
Project quality management in manufacturing
PRIZ Academy - 9 Windows Thinking Where to Invest Today to Win Tomorrow.pdf
Geodesy 1.pptx...............................................
UNIT 4 Total Quality Management .pptx
OOP with Java - Java Introduction (Basics)
M Tech Sem 1 Civil Engineering Environmental Sciences.pptx
Construction Project Organization Group 2.pptx
IOT PPTs Week 10 Lecture Material.pptx of NPTEL Smart Cities contd
Lecture Notes Electrical Wiring System Components
Mohammad Mahdi Farshadian CV - Prospective PhD Student 2026
composite construction of structures.pdf
Digital Logic Computer Design lecture notes
Embodied AI: Ushering in the Next Era of Intelligent Systems
Strings in CPP - Strings in C++ are sequences of characters used to store and...
MET 305 2019 SCHEME MODULE 2 COMPLETE.pptx
Sustainable Sites - Green Building Construction
Infosys Presentation by1.Riyan Bagwan 2.Samadhan Naiknavare 3.Gaurav Shinde 4...
July 2025 - Top 10 Read Articles in International Journal of Software Enginee...
CARTOGRAPHY AND GEOINFORMATION VISUALIZATION chapter1 NPTE (2).pptx
bas. eng. economics group 4 presentation 1.pptx
Project quality management in manufacturing

Strings

  • 2.  The string is actually a one-dimensional array of characters which is terminated by a null character '0'.  All the string handling functions are prototyped in: string.h header file. So while using any string related function, don't forget to include string.h.  String constants have double quote marks around them.  String constants can be assigned to a char array either with no size specified, or the size can also be specified, but don't forget to leave a space for the null character.
  • 3.  Strings are often needed to be manipulated by the programmer according to the need of a problem. Hence, C provides a variety of string handling functions.  String handling functions refers to a group of functions implementing various operations on strings.  Some of the operations performed by the string handling functions includes: › Length (number of characters in the string). › Concatenation (adding two are more strings) › Comparing two strings. › Substring (Extract substring from a given string) › Copy(copies one string over another)
  • 4.  The various string handling functions supported by C are as follows:  strlen() It is used to find the length of the string. syntax: strlen(string)  strcpy() It is used to copy one string to another. syntax: strcpy(string1,string2)  strcat() It is used to combine two strings. syntax: strcat(string1,string2)
  • 5.  strcmp() It is used to compare two strings. syntax: strcmp(string1,string2)  Returns 0 if two strings are equal.  Return value <0 if s1 is less than s2.  Return value >0 if s1 is greater than s2.  strrev() It used to reverse a string. syntax: strrev(string)  strlwr(), strupr() It used to change the case of a string. syntax: strlwr(string) strupr(string)
  • 6.  strncpy() It used to copy ‘n’ characters of one string to another.  strstr() It is used to determine the first occurrence of a given string in another string.  strncat() It appends source string to destination string up to specified length.  strspn() It is used to find up to what length two strings are identical.
  • 7.  strncmp() It is used to compare ‘n’ character of two strings.  strcmpi() It is used to compare two strings without regarding the case.  strnicmp() It is used to compare first ‘n’ characters of two strings without regarding the case.  strchr() It is used to determine the first occurrence of a given character in a string.  strrchr() It is used to determine the last occurrence of a given character in a string.
  • 8. #include<stdio.h> #include<conio.h> #include<string.h> void main() { char a[]="college"; int b; clrscr(); b=strlen(a); printf("nThe length of the string is %d",b); getch(); } Output: The length of the string is 7
  • 9. #include<stdio.h> #include<conio.h> #include<string.h> void main() { char a[ ]="IT"; char b[ ]="Dept"; clrscr(); strcpy(a,b); printf("nThe string is %s",a); getch(); } Output: The string is Dept
  • 10. #include<stdio.h> #include<conio.h> #include<string.h> void main() { char a[ ]="IT"; char b[ ]="Dept"; clrscr(); strcat(a,b); printf("nThe string is %s",a); getch(); } Output: The string is ITDept
  • 11. #include<stdio.h> #include<conio.h> #include<string.h> void main() { char a[ ]="itdept"; char b[ ]="it"; int i; clrscr(); i=strcmp(a,b); if(i==0) printf("nstrings are equal:%d",i); else if(i<0) printf("nstring1 is less than string2:%d",i);
  • 12. else printf("nstring1 is greater than string2:%d",i); getch(); } Output: string1 is greater than string2:100
  • 13. #include<stdio.h> #include<conio.h> #include<string.h> void main() { char a[ ]="itdept"; clrscr(); printf("nThe string is :%s",a); strupr(a); printf("nThe string after conversion to uppercase :%s",a); strlwr(a); printf("nThe string after conversion to lowercase :%s",a); getch(); }
  • 14. The string is : itdept The string after conversion to uppercase :ITDEPT The string after conversion to lowercase : itdept
  • 15. #include<stdio.h> #include<conio.h> #include<string.h> void main() { char a[ ]="Dept"; clrscr(); printf("nThe string is %s",strrev(a)); getch(); } Output: The string is tpeD
  • 16. #include<stdio.h> #include<conio.h> #include<string.h> void main() { char a[ ]="itdept"; char b[15]; int i=0; clrscr(); strncpy(b,a,2); b[2]='0'; printf("nThe string is :%s",b); getch(); } Output: The string is :it
  • 17. #include<stdio.h> #include<conio.h> #include<string.h> void main() { int len,i,j; char str[15]; clrscr(); printf("n Enter the string:"); scanf("%s",str); len=strlen(str);
  • 18. for(i=0,j=len-1;i<len/2;i++,j--) { if(str[i]!=str[j]) { printf("n The String is not a palindrome"); getch(); exit(0); } } printf("n The String is a palindrome"); getch(); } Output: Enter the string: abcba The String is a palindrome