SlideShare a Scribd company logo
Strings
Introduction
 A string is a sequence of characters that
is treated as a single data item.
 Any group of characters(except double
quote sign) defined between double
quotation marks is a string constant.
Example:
“Man is obviously made to think.”
 Normally, string is useful for storing data
like name, address, city etc.
Copyright ©2013 Yash Agarwal. All rights reserved.
Strings
 C implements the stringstring data structure using arrays of
type char.
 You have already used the string extensively.
 printf(“This program is terminated!n”);
 Since stringstring is an array, the declaration of a string is
the same as declaring a char array.
 char string_var[30];
 char string_var[20] = “Initial value”;
Copyright ©2013 Yash Agarwal. All rights reserved.
Memory Storage for a
String
 ASCII code is internally used to represent string in
memory.
 In ‘C’ each string is always ended with a nullnull
charactercharacter ‘0’‘0’.
 The characters after the null character are ignored.
 e.g., char str[20] = “Initial value”;
Copyright ©2013 Yash Agarwal. All rights reserved.
n i t i a l v a l u e ? ? …I 00
[0] [13]
Common operations
performed on strings
 Reading and writing strings
 Combining strings together
 Copying one string to another
 Comparing strings for equality
 Extracting a portion of a string
Copyright ©2013 Yash Agarwal. All rights reserved.
Input/Output of a
String
 The %s%s format specifier is used to represent string arguments in
printf and scanf.
 printf(“Topic: %sn”, string_var);
 The string can be right-justified by placing a positive number in
the format specifier .
 printf(“%8s%8s”, str);
 The string can be left-justified by placing a negative number in
the format specifier .
 Printf(“%-8s%-8s”, str);
Copyright ©2013 Yash Agarwal. All rights reserved.
An Example of
Manipulating String
with scanf and printf
Copyright ©2004 Pearson Addison-Wesley. All rights reserved.
The dept is the initial memory
address of the string argument. Thus
we don’t apply the & operator on it.
Execution of scanf
("%s", dept);
Copyright ©2004 Pearson Addison-Wesley. All rights reserved.
• Whenever encountering a white space, the scanning stops
and scanf places the null character at the end of the string.
• e.g., if the user types “MATH 1234 TR 1800,” the string
“MATH” along with ‘0’ is stored into dept.
String Library
Functions
 The string can not be copied by the
assignment operator ‘=’.
 e.g., “str = “Test String”” is not
valid.
 C provides string manipulating or built-in
functions in the “string.h” library.
 We require to include string.h header file
for using built-in string functions.
Copyright ©2013 Yash Agarwal. All rights reserved.
Some String Functions from
String.h
Function Purpose Example
strcpy Makes a copy of a
string
strcpy(s1, “Hi”);
strcat Appends a string to the
end of another string
strcat(s1, “more”);
strcmp Compare two strings
alphabetically
strcmp(s1, “Hu”);
strlen Returns the number of
characters in a string
strlen(“Hi”)
returns 2.
strtok Breaks a string into
tokens by delimiters.
strtok(“Hi, Chao”,
“ ,”);
Copyright ©2013 Yash Agarwal. All rights reserved. 9-10
Copyright ©2013 Yash Agarwal. All rights reserved. 9-11
Function Purpose Example
strrev Reverses the string s strrev(“Jay”);
Gives: yaJ
strupr Convert string to
uppercase
strupr(“Jay”);
Gives: JAY
strlwr Convert string to lower
case
strlwr(“Jay”);
Gives: jay
strncmp Compares first n
characters in a string
strncmp(s1,“Hi”)
returns 2.
Functions strcpy
and strncpy Function strcpy copies the string in the second
argument into the first argument.
 e.g., strcpy(dest , “test string”);
 The null characternull character is appended at the end
automatically.
 If source string is longer than the destination string, the
overflow characters may occupy the memory space
used by other variables.
 Function strncpy copies the string by specifying
the number of characters to copy.
 You have to place the null character manually.
 e.g., strncpy(dest , “test string”, 6); dest[6] = ‘0’;dest[6] = ‘0’;
 If source string is longer than the destination string, the
overflow characters are discarded automatically.Copyright ©2013 Yash Agarwal. All rights reserved.
Extracting Substring of
a String (1/2)
Copyright ©2004 Pearson Addison-Wesley. All rights reserved.
• We can use strncpy to extract substring of one string.
– e.g., strncpy(result, s1, 9);
Extracting Substring of
a String (2/2)
Copyright ©2004 Pearson Addison-Wesley. All rights reserved.
• e.g., strncpy(result, &s1[5]&s1[5], 2);
Functions strcat and
strlen
 Functions strcat and strncat concatenate
the fist string argument with the second string
argument.
 strcat(dest, “more..”);
 strncat(dest, “more..”, 3);
 Function strlen is often used to check the
length of a string (i.e., the number of
characters before the fist null character).
 e.g., dest[6] = “Hello”;
strncat(dest, “more”, 5-strlen(dest));
dest[5] = ‘0’;Copyright ©2013 Yash Agarwal. All rights reserved.
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.
Copyright ©2013 Yash Agarwal. All rights reserved.
Q
Character ‘Q’
Q 00
String “Q”
String Comparison
(1/2) Suppose there are two strings, str1 and str2.
 The condition str1 < str2 compare the initialinitial
memory addressmemory address of str1 and of str2.
 The comparison between two strings is done by
comparing each corresponding character in
them.
 The characters are compared against the ASCII table.
 “thrill” < “throw” since ‘i’ < ‘o’;
 “joy” < joyous“;
 The standard string comparison uses the strcmp
and strncmp functions.
Copyright ©2013 Yash Agarwal. All rights reserved.
String Comparison (2/2)
Relationship Returned Value Example
str1 < str2 Negative “Hello”< “Hi”
str1 = str2 0 “Hi” = “Hi”
str1 > str2 Positive “Hi” > “Hello”
Copyright ©2013 Yash Agarwal. All rights reserved. 9-18
• e.g., we can check if two strings are the same by
if(strcmp(str1, str2) != 0)
printf(“The two strings are
different!”);
Input/Output of
Characters and
Strings The stdio library provides getchar function which
gets the next character from the standard input.
 “ch = getchar();” is the same as “scanf(“%c”,
&ch);”
 Similar functions are putchar, gets, puts.
 For IO from/to the file, the stdio library also provides
corresponding functions.
 getc: reads a character from a file.
 Similar functions are putc, fgets, fputs.
Copyright ©2013 Yash Agarwal. All rights reserved.
Character Analysis and
Conversion
 The <ctype.h><ctype.h> library defines facilities for
character analysis and conversion.
Functions Description
isalpha Check if the argument is a letter
isdigit Check if the argument is one of the ten digits
isspace Check if argument is a space, newline or tab.
tolower Converts the lowercase letters in the
argument to upper case letters.Copyright ©2013 Yash Agarwal. All rights reserved. 9-20
Presentation By:
 F.Y. MECH-2 STUDENTS :
Name Id no.
Viraj Patel 100
Karan Parekh 103
Yash Agarwal 104
Pritesh Vaghela 105
Copyright ©2013 Yash Agarwal. All rights reserved.

More Related Content

What's hot

Strings
StringsStrings
Strings
Nilesh Dalvi
 
Strings IN C
Strings IN CStrings IN C
Strings IN C
yndaravind
 
Strinng Classes in c++
Strinng Classes in c++Strinng Classes in c++
Strinng Classes in c++Vikash Dhal
 
Strings in c
Strings in cStrings in c
Strings in c
vampugani
 
Java string handling
Java string handlingJava string handling
Java string handling
Salman Khan
 
String c
String cString c
Implementation Of String Functions In C
Implementation Of String Functions In CImplementation Of String Functions In C
Implementation Of String Functions In C
Fazila Sadia
 
String in c
String in cString in c
String in c
Suneel Dogra
 
String in c programming
String in c programmingString in c programming
String in c programming
Devan Thakur
 
Strings In OOP(Object oriented programming)
Strings In OOP(Object oriented programming)Strings In OOP(Object oriented programming)
Strings In OOP(Object oriented programming)
Danial Virk
 
Character array (strings)
Character array (strings)Character array (strings)
Character array (strings)
sangrampatil81
 
strings in c language and its importance
strings in c language and its importancestrings in c language and its importance
strings in c language and its importance
sirmanohar
 
Lecture 6
Lecture 6Lecture 6
Lecture 6
Mohammed Saleh
 
Handling of character strings C programming
Handling of character strings C programmingHandling of character strings C programming
Handling of character strings C programming
Appili Vamsi Krishna
 
Lecture 6
Lecture 6Lecture 6

What's hot (20)

14 ruby strings
14 ruby strings14 ruby strings
14 ruby strings
 
Strings
StringsStrings
Strings
 
05 c++-strings
05 c++-strings05 c++-strings
05 c++-strings
 
Strings IN C
Strings IN CStrings IN C
Strings IN C
 
Strings
StringsStrings
Strings
 
Strinng Classes in c++
Strinng Classes in c++Strinng Classes in c++
Strinng Classes in c++
 
Strings in c
Strings in cStrings in c
Strings in c
 
String Handling
String HandlingString Handling
String Handling
 
Java string handling
Java string handlingJava string handling
Java string handling
 
String c
String cString c
String c
 
Implementation Of String Functions In C
Implementation Of String Functions In CImplementation Of String Functions In C
Implementation Of String Functions In C
 
String in c
String in cString in c
String in c
 
String in c programming
String in c programmingString in c programming
String in c programming
 
Strings In OOP(Object oriented programming)
Strings In OOP(Object oriented programming)Strings In OOP(Object oriented programming)
Strings In OOP(Object oriented programming)
 
Character array (strings)
Character array (strings)Character array (strings)
Character array (strings)
 
Strings in Java
Strings in JavaStrings in Java
Strings in Java
 
strings in c language and its importance
strings in c language and its importancestrings in c language and its importance
strings in c language and its importance
 
Lecture 6
Lecture 6Lecture 6
Lecture 6
 
Handling of character strings C programming
Handling of character strings C programmingHandling of character strings C programming
Handling of character strings C programming
 
Lecture 6
Lecture 6Lecture 6
Lecture 6
 

Viewers also liked

Pointers In C
Pointers In CPointers In C
Pointers In C
Sriram Raj
 
function, storage class and array and strings
 function, storage class and array and strings function, storage class and array and strings
function, storage class and array and strings
Rai University
 
Unit 3. Input and Output
Unit 3. Input and OutputUnit 3. Input and Output
Unit 3. Input and Output
Ashim Lamichhane
 
Unit 8. Pointers
Unit 8. PointersUnit 8. Pointers
Unit 8. Pointers
Ashim Lamichhane
 
Unit 6. Arrays
Unit 6. ArraysUnit 6. Arrays
Unit 6. Arrays
Ashim Lamichhane
 
Pointers in C Programming
Pointers in C ProgrammingPointers in C Programming
Pointers in C Programming
Jasleen Kaur (Chandigarh University)
 
Computer Programming- Lecture 5
Computer Programming- Lecture 5 Computer Programming- Lecture 5
Computer Programming- Lecture 5
Dr. Md. Shohel Sayeed
 
Array in c language
Array in c languageArray in c language
Array in c languagehome
 

Viewers also liked (8)

Pointers In C
Pointers In CPointers In C
Pointers In C
 
function, storage class and array and strings
 function, storage class and array and strings function, storage class and array and strings
function, storage class and array and strings
 
Unit 3. Input and Output
Unit 3. Input and OutputUnit 3. Input and Output
Unit 3. Input and Output
 
Unit 8. Pointers
Unit 8. PointersUnit 8. Pointers
Unit 8. Pointers
 
Unit 6. Arrays
Unit 6. ArraysUnit 6. Arrays
Unit 6. Arrays
 
Pointers in C Programming
Pointers in C ProgrammingPointers in C Programming
Pointers in C Programming
 
Computer Programming- Lecture 5
Computer Programming- Lecture 5 Computer Programming- Lecture 5
Computer Programming- Lecture 5
 
Array in c language
Array in c languageArray in c language
Array in c language
 

Similar to Strings(2007)

[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++
Muhammad Hammad Waseem
 
introduction to strings in c programming
introduction to strings in c programmingintroduction to strings in c programming
introduction to strings in c programming
mikeymanjiro2090
 
String notes
String notesString notes
String notes
Prasadu Peddi
 
C q 3
C q 3C q 3
c programming
c programmingc programming
c programming
Arun Umrao
 
Strings CPU GTU
Strings CPU GTUStrings CPU GTU
Strings CPU GTU
Maharshi Dave
 
Matlab strings
Matlab stringsMatlab strings
Matlab strings
pramodkumar1804
 
9 character string &amp; string library
9  character string &amp; string library9  character string &amp; string library
9 character string &amp; string library
MomenMostafa
 
Strings in c mrs.sowmya jyothi
Strings in c mrs.sowmya jyothiStrings in c mrs.sowmya jyothi
Strings in c mrs.sowmya jyothi
Sowmya Jyothi
 
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
SowmyaJyothi3
 
CP-STRING (1).ppt
CP-STRING (1).pptCP-STRING (1).ppt
CP-STRING (1).ppt
mounikanarra3
 
CP-STRING.ppt
CP-STRING.pptCP-STRING.ppt
CP-STRING.ppt
TAPANDDRAW
 
CP-STRING.ppt
CP-STRING.pptCP-STRING.ppt
CP-STRING.ppt
arunatluri
 
Strings part2
Strings part2Strings part2
Strings part2
yndaravind
 
string in C
string in Cstring in C
CPSTRINGSARGAVISTRINGS.PPT
CPSTRINGSARGAVISTRINGS.PPTCPSTRINGSARGAVISTRINGS.PPT
CPSTRINGSARGAVISTRINGS.PPT
Sasideepa
 

Similar to Strings(2007) (20)

[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++
 
introduction to strings in c programming
introduction to strings in c programmingintroduction to strings in c programming
introduction to strings in c programming
 
String notes
String notesString notes
String notes
 
14 strings
14 strings14 strings
14 strings
 
C q 3
C q 3C q 3
C q 3
 
c programming
c programmingc programming
c programming
 
Strings CPU GTU
Strings CPU GTUStrings CPU GTU
Strings CPU GTU
 
Matlab strings
Matlab stringsMatlab strings
Matlab strings
 
9 character string &amp; string library
9  character string &amp; string library9  character string &amp; string library
9 character string &amp; string library
 
Strings
StringsStrings
Strings
 
Strings
StringsStrings
Strings
 
Strings
StringsStrings
Strings
 
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 MRS.SOWMYA JYOTHI.pdf
STRINGS IN C MRS.SOWMYA JYOTHI.pdfSTRINGS IN C MRS.SOWMYA JYOTHI.pdf
STRINGS IN C MRS.SOWMYA JYOTHI.pdf
 
CP-STRING (1).ppt
CP-STRING (1).pptCP-STRING (1).ppt
CP-STRING (1).ppt
 
CP-STRING.ppt
CP-STRING.pptCP-STRING.ppt
CP-STRING.ppt
 
CP-STRING.ppt
CP-STRING.pptCP-STRING.ppt
CP-STRING.ppt
 
Strings part2
Strings part2Strings part2
Strings part2
 
string in C
string in Cstring in C
string in C
 
CPSTRINGSARGAVISTRINGS.PPT
CPSTRINGSARGAVISTRINGS.PPTCPSTRINGSARGAVISTRINGS.PPT
CPSTRINGSARGAVISTRINGS.PPT
 

Recently uploaded

road safety engineering r s e unit 3.pdf
road safety engineering  r s e unit 3.pdfroad safety engineering  r s e unit 3.pdf
road safety engineering r s e unit 3.pdf
VENKATESHvenky89705
 
Design and Analysis of Algorithms-DP,Backtracking,Graphs,B&B
Design and Analysis of Algorithms-DP,Backtracking,Graphs,B&BDesign and Analysis of Algorithms-DP,Backtracking,Graphs,B&B
Design and Analysis of Algorithms-DP,Backtracking,Graphs,B&B
Sreedhar Chowdam
 
Hierarchical Digital Twin of a Naval Power System
Hierarchical Digital Twin of a Naval Power SystemHierarchical Digital Twin of a Naval Power System
Hierarchical Digital Twin of a Naval Power System
Kerry Sado
 
CME397 Surface Engineering- Professional Elective
CME397 Surface Engineering- Professional ElectiveCME397 Surface Engineering- Professional Elective
CME397 Surface Engineering- Professional Elective
karthi keyan
 
Gen AI Study Jams _ For the GDSC Leads in India.pdf
Gen AI Study Jams _ For the GDSC Leads in India.pdfGen AI Study Jams _ For the GDSC Leads in India.pdf
Gen AI Study Jams _ For the GDSC Leads in India.pdf
gdsczhcet
 
Recycled Concrete Aggregate in Construction Part III
Recycled Concrete Aggregate in Construction Part IIIRecycled Concrete Aggregate in Construction Part III
Recycled Concrete Aggregate in Construction Part III
Aditya Rajan Patra
 
RAT: Retrieval Augmented Thoughts Elicit Context-Aware Reasoning in Long-Hori...
RAT: Retrieval Augmented Thoughts Elicit Context-Aware Reasoning in Long-Hori...RAT: Retrieval Augmented Thoughts Elicit Context-Aware Reasoning in Long-Hori...
RAT: Retrieval Augmented Thoughts Elicit Context-Aware Reasoning in Long-Hori...
thanhdowork
 
Building Electrical System Design & Installation
Building Electrical System Design & InstallationBuilding Electrical System Design & Installation
Building Electrical System Design & Installation
symbo111
 
NO1 Uk best vashikaran specialist in delhi vashikaran baba near me online vas...
NO1 Uk best vashikaran specialist in delhi vashikaran baba near me online vas...NO1 Uk best vashikaran specialist in delhi vashikaran baba near me online vas...
NO1 Uk best vashikaran specialist in delhi vashikaran baba near me online vas...
Amil Baba Dawood bangali
 
一比一原版(IIT毕业证)伊利诺伊理工大学毕业证成绩单专业办理
一比一原版(IIT毕业证)伊利诺伊理工大学毕业证成绩单专业办理一比一原版(IIT毕业证)伊利诺伊理工大学毕业证成绩单专业办理
一比一原版(IIT毕业证)伊利诺伊理工大学毕业证成绩单专业办理
zwunae
 
CW RADAR, FMCW RADAR, FMCW ALTIMETER, AND THEIR PARAMETERS
CW RADAR, FMCW RADAR, FMCW ALTIMETER, AND THEIR PARAMETERSCW RADAR, FMCW RADAR, FMCW ALTIMETER, AND THEIR PARAMETERS
CW RADAR, FMCW RADAR, FMCW ALTIMETER, AND THEIR PARAMETERS
veerababupersonal22
 
一比一原版(SFU毕业证)西蒙菲莎大学毕业证成绩单如何办理
一比一原版(SFU毕业证)西蒙菲莎大学毕业证成绩单如何办理一比一原版(SFU毕业证)西蒙菲莎大学毕业证成绩单如何办理
一比一原版(SFU毕业证)西蒙菲莎大学毕业证成绩单如何办理
bakpo1
 
space technology lecture notes on satellite
space technology lecture notes on satellitespace technology lecture notes on satellite
space technology lecture notes on satellite
ongomchris
 
一比一原版(UofT毕业证)多伦多大学毕业证成绩单如何办理
一比一原版(UofT毕业证)多伦多大学毕业证成绩单如何办理一比一原版(UofT毕业证)多伦多大学毕业证成绩单如何办理
一比一原版(UofT毕业证)多伦多大学毕业证成绩单如何办理
ydteq
 
Final project report on grocery store management system..pdf
Final project report on grocery store management system..pdfFinal project report on grocery store management system..pdf
Final project report on grocery store management system..pdf
Kamal Acharya
 
AP LAB PPT.pdf ap lab ppt no title specific
AP LAB PPT.pdf ap lab ppt no title specificAP LAB PPT.pdf ap lab ppt no title specific
AP LAB PPT.pdf ap lab ppt no title specific
BrazilAccount1
 
HYDROPOWER - Hydroelectric power generation
HYDROPOWER - Hydroelectric power generationHYDROPOWER - Hydroelectric power generation
HYDROPOWER - Hydroelectric power generation
Robbie Edward Sayers
 
Nuclear Power Economics and Structuring 2024
Nuclear Power Economics and Structuring 2024Nuclear Power Economics and Structuring 2024
Nuclear Power Economics and Structuring 2024
Massimo Talia
 
在线办理(ANU毕业证书)澳洲国立大学毕业证录取通知书一模一样
在线办理(ANU毕业证书)澳洲国立大学毕业证录取通知书一模一样在线办理(ANU毕业证书)澳洲国立大学毕业证录取通知书一模一样
在线办理(ANU毕业证书)澳洲国立大学毕业证录取通知书一模一样
obonagu
 
Student information management system project report ii.pdf
Student information management system project report ii.pdfStudent information management system project report ii.pdf
Student information management system project report ii.pdf
Kamal Acharya
 

Recently uploaded (20)

road safety engineering r s e unit 3.pdf
road safety engineering  r s e unit 3.pdfroad safety engineering  r s e unit 3.pdf
road safety engineering r s e unit 3.pdf
 
Design and Analysis of Algorithms-DP,Backtracking,Graphs,B&B
Design and Analysis of Algorithms-DP,Backtracking,Graphs,B&BDesign and Analysis of Algorithms-DP,Backtracking,Graphs,B&B
Design and Analysis of Algorithms-DP,Backtracking,Graphs,B&B
 
Hierarchical Digital Twin of a Naval Power System
Hierarchical Digital Twin of a Naval Power SystemHierarchical Digital Twin of a Naval Power System
Hierarchical Digital Twin of a Naval Power System
 
CME397 Surface Engineering- Professional Elective
CME397 Surface Engineering- Professional ElectiveCME397 Surface Engineering- Professional Elective
CME397 Surface Engineering- Professional Elective
 
Gen AI Study Jams _ For the GDSC Leads in India.pdf
Gen AI Study Jams _ For the GDSC Leads in India.pdfGen AI Study Jams _ For the GDSC Leads in India.pdf
Gen AI Study Jams _ For the GDSC Leads in India.pdf
 
Recycled Concrete Aggregate in Construction Part III
Recycled Concrete Aggregate in Construction Part IIIRecycled Concrete Aggregate in Construction Part III
Recycled Concrete Aggregate in Construction Part III
 
RAT: Retrieval Augmented Thoughts Elicit Context-Aware Reasoning in Long-Hori...
RAT: Retrieval Augmented Thoughts Elicit Context-Aware Reasoning in Long-Hori...RAT: Retrieval Augmented Thoughts Elicit Context-Aware Reasoning in Long-Hori...
RAT: Retrieval Augmented Thoughts Elicit Context-Aware Reasoning in Long-Hori...
 
Building Electrical System Design & Installation
Building Electrical System Design & InstallationBuilding Electrical System Design & Installation
Building Electrical System Design & Installation
 
NO1 Uk best vashikaran specialist in delhi vashikaran baba near me online vas...
NO1 Uk best vashikaran specialist in delhi vashikaran baba near me online vas...NO1 Uk best vashikaran specialist in delhi vashikaran baba near me online vas...
NO1 Uk best vashikaran specialist in delhi vashikaran baba near me online vas...
 
一比一原版(IIT毕业证)伊利诺伊理工大学毕业证成绩单专业办理
一比一原版(IIT毕业证)伊利诺伊理工大学毕业证成绩单专业办理一比一原版(IIT毕业证)伊利诺伊理工大学毕业证成绩单专业办理
一比一原版(IIT毕业证)伊利诺伊理工大学毕业证成绩单专业办理
 
CW RADAR, FMCW RADAR, FMCW ALTIMETER, AND THEIR PARAMETERS
CW RADAR, FMCW RADAR, FMCW ALTIMETER, AND THEIR PARAMETERSCW RADAR, FMCW RADAR, FMCW ALTIMETER, AND THEIR PARAMETERS
CW RADAR, FMCW RADAR, FMCW ALTIMETER, AND THEIR PARAMETERS
 
一比一原版(SFU毕业证)西蒙菲莎大学毕业证成绩单如何办理
一比一原版(SFU毕业证)西蒙菲莎大学毕业证成绩单如何办理一比一原版(SFU毕业证)西蒙菲莎大学毕业证成绩单如何办理
一比一原版(SFU毕业证)西蒙菲莎大学毕业证成绩单如何办理
 
space technology lecture notes on satellite
space technology lecture notes on satellitespace technology lecture notes on satellite
space technology lecture notes on satellite
 
一比一原版(UofT毕业证)多伦多大学毕业证成绩单如何办理
一比一原版(UofT毕业证)多伦多大学毕业证成绩单如何办理一比一原版(UofT毕业证)多伦多大学毕业证成绩单如何办理
一比一原版(UofT毕业证)多伦多大学毕业证成绩单如何办理
 
Final project report on grocery store management system..pdf
Final project report on grocery store management system..pdfFinal project report on grocery store management system..pdf
Final project report on grocery store management system..pdf
 
AP LAB PPT.pdf ap lab ppt no title specific
AP LAB PPT.pdf ap lab ppt no title specificAP LAB PPT.pdf ap lab ppt no title specific
AP LAB PPT.pdf ap lab ppt no title specific
 
HYDROPOWER - Hydroelectric power generation
HYDROPOWER - Hydroelectric power generationHYDROPOWER - Hydroelectric power generation
HYDROPOWER - Hydroelectric power generation
 
Nuclear Power Economics and Structuring 2024
Nuclear Power Economics and Structuring 2024Nuclear Power Economics and Structuring 2024
Nuclear Power Economics and Structuring 2024
 
在线办理(ANU毕业证书)澳洲国立大学毕业证录取通知书一模一样
在线办理(ANU毕业证书)澳洲国立大学毕业证录取通知书一模一样在线办理(ANU毕业证书)澳洲国立大学毕业证录取通知书一模一样
在线办理(ANU毕业证书)澳洲国立大学毕业证录取通知书一模一样
 
Student information management system project report ii.pdf
Student information management system project report ii.pdfStudent information management system project report ii.pdf
Student information management system project report ii.pdf
 

Strings(2007)

  • 2. Introduction  A string is a sequence of characters that is treated as a single data item.  Any group of characters(except double quote sign) defined between double quotation marks is a string constant. Example: “Man is obviously made to think.”  Normally, string is useful for storing data like name, address, city etc. Copyright ©2013 Yash Agarwal. All rights reserved.
  • 3. Strings  C implements the stringstring data structure using arrays of type char.  You have already used the string extensively.  printf(“This program is terminated!n”);  Since stringstring is an array, the declaration of a string is the same as declaring a char array.  char string_var[30];  char string_var[20] = “Initial value”; Copyright ©2013 Yash Agarwal. All rights reserved.
  • 4. Memory Storage for a String  ASCII code is internally used to represent string in memory.  In ‘C’ each string is always ended with a nullnull charactercharacter ‘0’‘0’.  The characters after the null character are ignored.  e.g., char str[20] = “Initial value”; Copyright ©2013 Yash Agarwal. All rights reserved. n i t i a l v a l u e ? ? …I 00 [0] [13]
  • 5. Common operations performed on strings  Reading and writing strings  Combining strings together  Copying one string to another  Comparing strings for equality  Extracting a portion of a string Copyright ©2013 Yash Agarwal. All rights reserved.
  • 6. Input/Output of a String  The %s%s format specifier is used to represent string arguments in printf and scanf.  printf(“Topic: %sn”, string_var);  The string can be right-justified by placing a positive number in the format specifier .  printf(“%8s%8s”, str);  The string can be left-justified by placing a negative number in the format specifier .  Printf(“%-8s%-8s”, str); Copyright ©2013 Yash Agarwal. All rights reserved.
  • 7. An Example of Manipulating String with scanf and printf Copyright ©2004 Pearson Addison-Wesley. All rights reserved. The dept is the initial memory address of the string argument. Thus we don’t apply the & operator on it.
  • 8. Execution of scanf ("%s", dept); Copyright ©2004 Pearson Addison-Wesley. All rights reserved. • Whenever encountering a white space, the scanning stops and scanf places the null character at the end of the string. • e.g., if the user types “MATH 1234 TR 1800,” the string “MATH” along with ‘0’ is stored into dept.
  • 9. String Library Functions  The string can not be copied by the assignment operator ‘=’.  e.g., “str = “Test String”” is not valid.  C provides string manipulating or built-in functions in the “string.h” library.  We require to include string.h header file for using built-in string functions. Copyright ©2013 Yash Agarwal. All rights reserved.
  • 10. Some String Functions from String.h Function Purpose Example strcpy Makes a copy of a string strcpy(s1, “Hi”); strcat Appends a string to the end of another string strcat(s1, “more”); strcmp Compare two strings alphabetically strcmp(s1, “Hu”); strlen Returns the number of characters in a string strlen(“Hi”) returns 2. strtok Breaks a string into tokens by delimiters. strtok(“Hi, Chao”, “ ,”); Copyright ©2013 Yash Agarwal. All rights reserved. 9-10
  • 11. Copyright ©2013 Yash Agarwal. All rights reserved. 9-11 Function Purpose Example strrev Reverses the string s strrev(“Jay”); Gives: yaJ strupr Convert string to uppercase strupr(“Jay”); Gives: JAY strlwr Convert string to lower case strlwr(“Jay”); Gives: jay strncmp Compares first n characters in a string strncmp(s1,“Hi”) returns 2.
  • 12. Functions strcpy and strncpy Function strcpy copies the string in the second argument into the first argument.  e.g., strcpy(dest , “test string”);  The null characternull character is appended at the end automatically.  If source string is longer than the destination string, the overflow characters may occupy the memory space used by other variables.  Function strncpy copies the string by specifying the number of characters to copy.  You have to place the null character manually.  e.g., strncpy(dest , “test string”, 6); dest[6] = ‘0’;dest[6] = ‘0’;  If source string is longer than the destination string, the overflow characters are discarded automatically.Copyright ©2013 Yash Agarwal. All rights reserved.
  • 13. Extracting Substring of a String (1/2) Copyright ©2004 Pearson Addison-Wesley. All rights reserved. • We can use strncpy to extract substring of one string. – e.g., strncpy(result, s1, 9);
  • 14. Extracting Substring of a String (2/2) Copyright ©2004 Pearson Addison-Wesley. All rights reserved. • e.g., strncpy(result, &s1[5]&s1[5], 2);
  • 15. Functions strcat and strlen  Functions strcat and strncat concatenate the fist string argument with the second string argument.  strcat(dest, “more..”);  strncat(dest, “more..”, 3);  Function strlen is often used to check the length of a string (i.e., the number of characters before the fist null character).  e.g., dest[6] = “Hello”; strncat(dest, “more”, 5-strlen(dest)); dest[5] = ‘0’;Copyright ©2013 Yash Agarwal. All rights reserved.
  • 16. 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. Copyright ©2013 Yash Agarwal. All rights reserved. Q Character ‘Q’ Q 00 String “Q”
  • 17. String Comparison (1/2) Suppose there are two strings, str1 and str2.  The condition str1 < str2 compare the initialinitial memory addressmemory address of str1 and of str2.  The comparison between two strings is done by comparing each corresponding character in them.  The characters are compared against the ASCII table.  “thrill” < “throw” since ‘i’ < ‘o’;  “joy” < joyous“;  The standard string comparison uses the strcmp and strncmp functions. Copyright ©2013 Yash Agarwal. All rights reserved.
  • 18. String Comparison (2/2) Relationship Returned Value Example str1 < str2 Negative “Hello”< “Hi” str1 = str2 0 “Hi” = “Hi” str1 > str2 Positive “Hi” > “Hello” Copyright ©2013 Yash Agarwal. All rights reserved. 9-18 • e.g., we can check if two strings are the same by if(strcmp(str1, str2) != 0) printf(“The two strings are different!”);
  • 19. Input/Output of Characters and Strings The stdio library provides getchar function which gets the next character from the standard input.  “ch = getchar();” is the same as “scanf(“%c”, &ch);”  Similar functions are putchar, gets, puts.  For IO from/to the file, the stdio library also provides corresponding functions.  getc: reads a character from a file.  Similar functions are putc, fgets, fputs. Copyright ©2013 Yash Agarwal. All rights reserved.
  • 20. Character Analysis and Conversion  The <ctype.h><ctype.h> library defines facilities for character analysis and conversion. Functions Description isalpha Check if the argument is a letter isdigit Check if the argument is one of the ten digits isspace Check if argument is a space, newline or tab. tolower Converts the lowercase letters in the argument to upper case letters.Copyright ©2013 Yash Agarwal. All rights reserved. 9-20
  • 21. Presentation By:  F.Y. MECH-2 STUDENTS : Name Id no. Viraj Patel 100 Karan Parekh 103 Yash Agarwal 104 Pritesh Vaghela 105 Copyright ©2013 Yash Agarwal. All rights reserved.