SlideShare a Scribd company logo
1 of 15
CHARACTER ARRAYS AND STRINGS
-Kishore Kumar
STRINGS
• A string is a collection of characters that are enclosed within double quotes (" ").
• A string can also be called a character array.*It can be treated as a single data item
and terminated by null character '0’.
• C language does not support strings as a data type.
• A string is actually one - dimensional array of characters in C language.
Example:
The String "good" contains 5 characters including '0' character which
is automatically added by the compiler at the end of the string.
STRINGS
Declaring and initializing a string variable:
There are different ways to initialize a character array variable
Remember when you initialize a character array by listing all of its character
separately then you must supply the ‘0’ character explicitly
STRINGS
Some invalid ways to initialize a character array
STRING INPUT AND OUTPUT:
• Input function scanf() can be used with %s format specifier to read a a string input from the
terminal but there’s a problem with it, it terminates its input on the first whitespace it
encounters
• However, C supports a format specification known as the edit set conversion code %[..] that
can be used to read a line containing a variety of characters, including white spaces
STRING HANDLING FUNCTIONS:
• C language supports a large number of string handling functions that can be used
to carry out many of the string manipulations.
• The operations such as copying a string, joining two strings, extracting a portion of
the string, determining the length of a string, etc., cannot be done using arithmetic
operators.
• The string-based library functions are used to program this type of operations and
they are located in the header file <string.h> , it should be included in the program
to access the functions.
STRING HANDLING FUNCTIONS:
Method Description
It is used to concatenate(combine) two strings
strlen() It is used to show length of a string
strrev() It is used to show reverse of a string
strcpy() Copies one string into another
strcmp() It is used to compare two strings
strcat()
STRING HANDLING FUNCTIONS:
We are not able to use + operator to join two strings. The function strcat( ) is used for joining two
strings.
strcat():
Syntax:
strcat(s1,s2);
Example:
Output:
kishorekumar
;
STRING HANDLING FUNCTIONS:
the function, strlen( ) is used to find the length of the given string.
strln():
Syntax:
strlen(str);
Example:
Output:
5
STRING HANDLING FUNCTIONS:
The strrev( ) function is used to reverse the given string expression.
strrev():
Syntax:
strrev(s1);
Example:
Output:
Enter your string:Kishore
Your reversed strings is erohisk
STRING HANDLING FUNCTIONS:
The function strcpy( ) is used to copy the content of one string into another.
strcpy():
Syntax:
strcpy(s1);
Example:
Output:
StudyTonight
STRING HANDLING FUNCTIONS:
The function is used to compare two strings. To compare any numeric values we use relational
operators. By using these operators we cannot compare strings. The strcmp( ) performs the function of
comparison.
strcmp():
Syntax:
strcmp(s1,s2);
NOTE:
The result of comparison is obtained by calculating the difference between the ASCII values of the
corresponding characters.
• Where s1 and s2 are string variables. This function returns any one of
the three possible results.
• Result is 0 when both the strings are equal. (s1=s2)
• Result is Positive value, if s1 is greater than s2.(s1>s2)
• Result is Negative if s1 is less than s2.(s1<s2)
STRING HANDLING FUNCTIONS:
The function is used to compare two strings. To compare any numeric values we use relational
operators. By using these operators we cannot compare strings. The strcmp( ) performs the function of
comparison.
strcmp():
Example:
Output:
1
READ AND WRITE STRINGS IN C:
Different methods to read and write strings in C:
• gets() and fgets() function are used to read the strings in C
• Strings in C can be displayed using puts() and fputs() functions
and also printf() function can be used with %s format code
• fscant() and fprint() functions are used to get input and display the
the output in c respectively
THANK YOU!

More Related Content

Similar to Character Arrays and strings in c language

Engineering CS 5th Sem Python Module -2.pptx
Engineering CS 5th Sem Python Module -2.pptxEngineering CS 5th Sem Python Module -2.pptx
Engineering CS 5th Sem Python Module -2.pptxhardii0991
 
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++ Samsil Arefin
 
Operation on string presentation
Operation on string presentationOperation on string presentation
Operation on string presentationAliul Kadir Akib
 
Lesson in Strings for C Programming Lessons
Lesson in Strings for C Programming LessonsLesson in Strings for C Programming Lessons
Lesson in Strings for C Programming LessonsJamesChristianGadian
 
Strings-Computer programming
Strings-Computer programmingStrings-Computer programming
Strings-Computer programmingnmahi96
 
Console I/o & basics of array and strings.pptx
Console I/o & basics of array and strings.pptxConsole I/o & basics of array and strings.pptx
Console I/o & basics of array and strings.pptxPRASENJITMORE2
 
C UNIT-3 PREPARED BY M V B REDDY
C UNIT-3 PREPARED BY M V B REDDYC UNIT-3 PREPARED BY M V B REDDY
C UNIT-3 PREPARED BY M V B REDDYRajeshkumar Reddy
 
Bsc cs i pic u-4 function, storage class and array and strings
Bsc cs i pic u-4 function, storage class and array and stringsBsc cs i pic u-4 function, storage class and array and strings
Bsc cs i pic u-4 function, storage class and array and stringsRai University
 
Btech i pic u-4 function, storage class and array and strings
Btech i pic u-4 function, storage class and array and stringsBtech i pic u-4 function, storage class and array and strings
Btech i pic u-4 function, storage class and array and stringsRai University
 
Functions torage class and array and strings-
Functions torage class and array and strings-Functions torage class and array and strings-
Functions torage class and array and strings-aneebkmct
 

Similar to Character Arrays and strings in c language (20)

Engineering CS 5th Sem Python Module -2.pptx
Engineering CS 5th Sem Python Module -2.pptxEngineering CS 5th Sem Python Module -2.pptx
Engineering CS 5th Sem Python Module -2.pptx
 
String functions in C
String functions in CString functions in C
String functions in C
 
Strings in c++
Strings in c++Strings in c++
Strings in 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++
 
Strings
StringsStrings
Strings
 
Operation on string presentation
Operation on string presentationOperation on string presentation
Operation on string presentation
 
Lesson in Strings for C Programming Lessons
Lesson in Strings for C Programming LessonsLesson in Strings for C Programming Lessons
Lesson in Strings for C Programming Lessons
 
Strings-Computer programming
Strings-Computer programmingStrings-Computer programming
Strings-Computer programming
 
String handling
String handlingString handling
String handling
 
String notes
String notesString notes
String notes
 
Console I/o & basics of array and strings.pptx
Console I/o & basics of array and strings.pptxConsole I/o & basics of array and strings.pptx
Console I/o & basics of array and strings.pptx
 
Savitch ch 08
Savitch ch 08Savitch ch 08
Savitch ch 08
 
C UNIT-3 PREPARED BY M V B REDDY
C UNIT-3 PREPARED BY M V B REDDYC UNIT-3 PREPARED BY M V B REDDY
C UNIT-3 PREPARED BY M V B REDDY
 
Bsc cs i pic u-4 function, storage class and array and strings
Bsc cs i pic u-4 function, storage class and array and stringsBsc cs i pic u-4 function, storage class and array and strings
Bsc cs i pic u-4 function, storage class and array and strings
 
Week6_P_String.pptx
Week6_P_String.pptxWeek6_P_String.pptx
Week6_P_String.pptx
 
[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++
 
COm1407: Character & Strings
COm1407: Character & StringsCOm1407: Character & Strings
COm1407: Character & Strings
 
Btech i pic u-4 function, storage class and array and strings
Btech i pic u-4 function, storage class and array and stringsBtech i pic u-4 function, storage class and array and strings
Btech i pic u-4 function, storage class and array and strings
 
Functions torage class and array and strings-
Functions torage class and array and strings-Functions torage class and array and strings-
Functions torage class and array and strings-
 
C- language Lecture 5
C- language Lecture 5C- language Lecture 5
C- language Lecture 5
 

Recently uploaded

Separation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesSeparation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesFatimaKhan178732
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxGaneshChakor2
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introductionMaksud Ahmed
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...EduSkills OECD
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Sapana Sha
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingTechSoup
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptxVS Mahajan Coaching Centre
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)eniolaolutunde
 
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991RKavithamani
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxSayali Powar
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactdawncurless
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfsanyamsingh5019
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxNirmalaLoungPoorunde1
 
Privatization and Disinvestment - Meaning, Objectives, Advantages and Disadva...
Privatization and Disinvestment - Meaning, Objectives, Advantages and Disadva...Privatization and Disinvestment - Meaning, Objectives, Advantages and Disadva...
Privatization and Disinvestment - Meaning, Objectives, Advantages and Disadva...RKavithamani
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdfQucHHunhnh
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxiammrhaywood
 
URLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website AppURLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website AppCeline George
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdfQucHHunhnh
 

Recently uploaded (20)

Separation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesSeparation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and Actinides
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptx
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introduction
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
 
Mattingly "AI & Prompt Design: The Basics of Prompt Design"
Mattingly "AI & Prompt Design: The Basics of Prompt Design"Mattingly "AI & Prompt Design: The Basics of Prompt Design"
Mattingly "AI & Prompt Design: The Basics of Prompt Design"
 
Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy Consulting
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)
 
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impact
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdf
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptx
 
Privatization and Disinvestment - Meaning, Objectives, Advantages and Disadva...
Privatization and Disinvestment - Meaning, Objectives, Advantages and Disadva...Privatization and Disinvestment - Meaning, Objectives, Advantages and Disadva...
Privatization and Disinvestment - Meaning, Objectives, Advantages and Disadva...
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
 
URLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website AppURLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website App
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdf
 

Character Arrays and strings in c language

  • 1. CHARACTER ARRAYS AND STRINGS -Kishore Kumar
  • 2. STRINGS • A string is a collection of characters that are enclosed within double quotes (" "). • A string can also be called a character array.*It can be treated as a single data item and terminated by null character '0’. • C language does not support strings as a data type. • A string is actually one - dimensional array of characters in C language. Example: The String "good" contains 5 characters including '0' character which is automatically added by the compiler at the end of the string.
  • 3. STRINGS Declaring and initializing a string variable: There are different ways to initialize a character array variable Remember when you initialize a character array by listing all of its character separately then you must supply the ‘0’ character explicitly
  • 4. STRINGS Some invalid ways to initialize a character array
  • 5. STRING INPUT AND OUTPUT: • Input function scanf() can be used with %s format specifier to read a a string input from the terminal but there’s a problem with it, it terminates its input on the first whitespace it encounters • However, C supports a format specification known as the edit set conversion code %[..] that can be used to read a line containing a variety of characters, including white spaces
  • 6. STRING HANDLING FUNCTIONS: • C language supports a large number of string handling functions that can be used to carry out many of the string manipulations. • The operations such as copying a string, joining two strings, extracting a portion of the string, determining the length of a string, etc., cannot be done using arithmetic operators. • The string-based library functions are used to program this type of operations and they are located in the header file <string.h> , it should be included in the program to access the functions.
  • 7. STRING HANDLING FUNCTIONS: Method Description It is used to concatenate(combine) two strings strlen() It is used to show length of a string strrev() It is used to show reverse of a string strcpy() Copies one string into another strcmp() It is used to compare two strings strcat()
  • 8. STRING HANDLING FUNCTIONS: We are not able to use + operator to join two strings. The function strcat( ) is used for joining two strings. strcat(): Syntax: strcat(s1,s2); Example: Output: kishorekumar ;
  • 9. STRING HANDLING FUNCTIONS: the function, strlen( ) is used to find the length of the given string. strln(): Syntax: strlen(str); Example: Output: 5
  • 10. STRING HANDLING FUNCTIONS: The strrev( ) function is used to reverse the given string expression. strrev(): Syntax: strrev(s1); Example: Output: Enter your string:Kishore Your reversed strings is erohisk
  • 11. STRING HANDLING FUNCTIONS: The function strcpy( ) is used to copy the content of one string into another. strcpy(): Syntax: strcpy(s1); Example: Output: StudyTonight
  • 12. STRING HANDLING FUNCTIONS: The function is used to compare two strings. To compare any numeric values we use relational operators. By using these operators we cannot compare strings. The strcmp( ) performs the function of comparison. strcmp(): Syntax: strcmp(s1,s2); NOTE: The result of comparison is obtained by calculating the difference between the ASCII values of the corresponding characters. • Where s1 and s2 are string variables. This function returns any one of the three possible results. • Result is 0 when both the strings are equal. (s1=s2) • Result is Positive value, if s1 is greater than s2.(s1>s2) • Result is Negative if s1 is less than s2.(s1<s2)
  • 13. STRING HANDLING FUNCTIONS: The function is used to compare two strings. To compare any numeric values we use relational operators. By using these operators we cannot compare strings. The strcmp( ) performs the function of comparison. strcmp(): Example: Output: 1
  • 14. READ AND WRITE STRINGS IN C: Different methods to read and write strings in C: • gets() and fgets() function are used to read the strings in C • Strings in C can be displayed using puts() and fputs() functions and also printf() function can be used with %s format code • fscant() and fprint() functions are used to get input and display the the output in c respectively