SlideShare a Scribd company logo
2
Most read
3
Most read
5
Most read
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

PDF
Character Array and String
PPT
358 33 powerpoint-slides_3-pointers_chapter-3
PPTX
Unit 8. Pointers
PPTX
Structure in c language
PDF
C Pointers
PPTX
Pointer in C++
PDF
STRUCTURE AND UNION IN C MRS.SOWMYA JYOTHI.pdf
PDF
C++ tokens and expressions
Character Array and String
358 33 powerpoint-slides_3-pointers_chapter-3
Unit 8. Pointers
Structure in c language
C Pointers
Pointer in C++
STRUCTURE AND UNION IN C MRS.SOWMYA JYOTHI.pdf
C++ tokens and expressions

What's hot (20)

PPT
Strings
PPT
RECURSION IN C
PPTX
concept of Array, 1D & 2D array
PPTX
Recursive Function
PDF
Data structure using c++
PPT
Searching in c language
PPTX
Functions in c
PPT
Strings
PPT
Pointer in C
PPTX
Structure in C language
PPTX
Pointer arithmetic in c
PPT
358 33 powerpoint-slides_7-structures_chapter-7
PPTX
User defined functions in C
PPTX
C Programming: Structure and Union
PPTX
Variables in python
PPTX
C Structures and Unions
PPT
C++ Returning Objects
PPTX
Union in c language
PPT
Strings Functions in C Programming
DOC
String in c
Strings
RECURSION IN C
concept of Array, 1D & 2D array
Recursive Function
Data structure using c++
Searching in c language
Functions in c
Strings
Pointer in C
Structure in C language
Pointer arithmetic in c
358 33 powerpoint-slides_7-structures_chapter-7
User defined functions in C
C Programming: Structure and Union
Variables in python
C Structures and Unions
C++ Returning Objects
Union in c language
Strings Functions in C Programming
String in c
Ad

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

PDF
STRINGS IN C MRS.SOWMYA JYOTHI.pdf
PDF
Strings in c mrs.sowmya jyothi
PPTX
Handling of character strings C programming
PDF
Principals of Programming in CModule -5.pdfModule-4.pdf
PDF
[ITP - Lecture 17] Strings in C/C++
PPTX
All_About_Strings_in_C_Programming.pptxn
DOCX
Unitii string
PPTX
Week6_P_String.pptx
PPT
Strings(2007)
PPTX
STRING FUNCTION - Programming in C.pptx
PDF
Strings part2
PPT
14 strings
PPTX
Strings CPU GTU
PPTX
programming for problem solving using C-STRINGSc
PPT
Strings in c
PPTX
Computer Programming Utilities the subject of BE first year students, and thi...
PPTX
String_Slide.pptxStructure.pptxStructure.pptxStructure.pptxStructure.pptx
PPTX
String predefined functions in C programming
PPTX
C programming - String
PPTX
CSE 1102 - Lecture_7 - Strings_in_C.pptx
STRINGS IN C MRS.SOWMYA JYOTHI.pdf
Strings in c mrs.sowmya jyothi
Handling of character strings C programming
Principals of Programming in CModule -5.pdfModule-4.pdf
[ITP - Lecture 17] Strings in C/C++
All_About_Strings_in_C_Programming.pptxn
Unitii string
Week6_P_String.pptx
Strings(2007)
STRING FUNCTION - Programming in C.pptx
Strings part2
14 strings
Strings CPU GTU
programming for problem solving using C-STRINGSc
Strings in c
Computer Programming Utilities the subject of BE first year students, and thi...
String_Slide.pptxStructure.pptxStructure.pptxStructure.pptxStructure.pptx
String predefined functions in C programming
C programming - String
CSE 1102 - Lecture_7 - Strings_in_C.pptx
Ad

Recently uploaded (20)

PDF
ANTIBIOTICS.pptx.pdf………………… xxxxxxxxxxxxx
PPTX
Pharma ospi slides which help in ospi learning
PDF
Supply Chain Operations Speaking Notes -ICLT Program
PDF
Chapter 2 Heredity, Prenatal Development, and Birth.pdf
PPTX
human mycosis Human fungal infections are called human mycosis..pptx
PDF
Insiders guide to clinical Medicine.pdf
PDF
FourierSeries-QuestionsWithAnswers(Part-A).pdf
PPTX
school management -TNTEU- B.Ed., Semester II Unit 1.pptx
PPTX
Cell Structure & Organelles in detailed.
PDF
102 student loan defaulters named and shamed – Is someone you know on the list?
PDF
Pre independence Education in Inndia.pdf
PPTX
Introduction_to_Human_Anatomy_and_Physiology_for_B.Pharm.pptx
PDF
Origin of periodic table-Mendeleev’s Periodic-Modern Periodic table
PPTX
Final Presentation General Medicine 03-08-2024.pptx
PDF
BÀI TẬP BỔ TRỢ 4 KỸ NĂNG TIẾNG ANH 9 GLOBAL SUCCESS - CẢ NĂM - BÁM SÁT FORM Đ...
PDF
Complications of Minimal Access Surgery at WLH
PPTX
PPH.pptx obstetrics and gynecology in nursing
PDF
O5-L3 Freight Transport Ops (International) V1.pdf
PDF
Abdominal Access Techniques with Prof. Dr. R K Mishra
PPTX
master seminar digital applications in india
ANTIBIOTICS.pptx.pdf………………… xxxxxxxxxxxxx
Pharma ospi slides which help in ospi learning
Supply Chain Operations Speaking Notes -ICLT Program
Chapter 2 Heredity, Prenatal Development, and Birth.pdf
human mycosis Human fungal infections are called human mycosis..pptx
Insiders guide to clinical Medicine.pdf
FourierSeries-QuestionsWithAnswers(Part-A).pdf
school management -TNTEU- B.Ed., Semester II Unit 1.pptx
Cell Structure & Organelles in detailed.
102 student loan defaulters named and shamed – Is someone you know on the list?
Pre independence Education in Inndia.pdf
Introduction_to_Human_Anatomy_and_Physiology_for_B.Pharm.pptx
Origin of periodic table-Mendeleev’s Periodic-Modern Periodic table
Final Presentation General Medicine 03-08-2024.pptx
BÀI TẬP BỔ TRỢ 4 KỸ NĂNG TIẾNG ANH 9 GLOBAL SUCCESS - CẢ NĂM - BÁM SÁT FORM Đ...
Complications of Minimal Access Surgery at WLH
PPH.pptx obstetrics and gynecology in nursing
O5-L3 Freight Transport Ops (International) V1.pdf
Abdominal Access Techniques with Prof. Dr. R K Mishra
master seminar digital applications in india

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