SlideShare a Scribd company logo
1 of 43
Chapter - 7
• Introduction
• Representation of string
• Operation on string
• String is a primitive data structure.
• It is represented as sequence of
characters.
•“hello” = ‘h’, ’e’, ’l’, ’l’, ’o’
Define :-
Char name[20]; // 1D array
Here name is array of characters and
treated as string.
Size of name is 20
Char name[20]=“SDS”;
Char name[20]={‘S’, ’D’, ’S’,’0’};
‘S’ ‘D’ ‘S’ ‘0’ blank blank
Char name[ ]=“Diploma”;
Size will be allocated 8 (string
length+1) as ‘0’ will be counted.
Char name[ ][ ]={“mahesh”,
“suresh”, “mukesh”, “ramesh”};
‘m’ ‘a’ ‘h’ ‘e’ ‘s’ ‘h’ ‘0’
‘s’ ‘u’ ‘r’ ‘e’ s’ ‘h’ ‘0’
‘m’ ‘u’ ‘k’ ‘e’ s’ ‘h’ ‘0’
‘r’ ‘a’ ‘m’ ‘e’ s’ ‘h’ ‘0’
Char name[20]=“SDS”;
‘S’ ‘D’ ‘S’ ‘0’ blank blank
1. Initialize len =0;
2. Perform following steps until len reaches to ‘0’
i) otherwise increment value of len by1.
3. return len.
len
int strlen(char str[])
{
int len;
for(len=0;str[len] !=‘0’;len++);
return len;
}
int strlen(char str[]);
void main()
{ int length;
char name[20];
clrscr();
gets(name);
length=strlen(name);
printf("length is : %d",length);
getch();
}
int strlen(char str[])
{
int len;
for(len=0;str[len] !='0';len++);
return len;
}
Char name[20]=“SDSRK”;
‘S’ ‘D’ ‘S’ ‘R’ ‘K’ ‘0’ blank
i j
‘S’ ‘D’ ‘S’ ‘R’ ‘K’ ‘0’ blank
i j
s
k
Char name[20]=“SDSRK”;
‘K’ ‘D’ ‘S’ ‘r’ ‘S’ ‘0’ blank
i j
D R
Char name[20]=“SDSRK”;
‘K’ ‘R’ ‘S’ ‘D’ ‘S’ ‘0’ blank
ij
1. Find length of string
2. Initialize i=0 and j=length-1.
3. Perform following steps till i less than length/2
i) exchange the element at ith and jth position.
ii) increment i by 1
iii) decrement j by 1
Char name[20]=“SDSRK”;
void reverse(char str[])
{
int i,j,len;
char temp;
for(len=0;str[len]!='0';len++);
for(i=0,j=len-1;i<len/2;i++,j--)
{
temp=str[i];
str[i]=str[j];
str[j]=temp;
}
return;
}
‘S’ ‘D’ ‘S’ ‘0’ blank blank blank
‘R’ ‘K’ ‘U’ ‘0’ blank blank
i
j
R
‘S’ ‘D’ ‘S’ ‘R’ blank blank blank
‘R’ ‘K’ ‘U’ ‘0’ blank blank
i
j
K
‘S’ ‘D’ ‘S’ ‘R’ ‘K’ blank blank
‘R’ ‘K’ ‘U’ ‘0’ blank blank
i
j
U
‘S’ ‘D’ ‘S’ ‘R’ ‘K’ ‘U’ blank
‘R’ ‘K’ ‘U’ ‘0’ blank blank
i
j
‘0’
‘S’ ‘D’ ‘S’ ‘R’ ‘K’ ‘U’ ‘0’ blank
‘R’ ‘K’ ‘U’ ‘0’ blank blank
i
j
1. Find length of string1.
2. Find length of string2.
3. Initialize i=length of string1 and j to 0.
4. Perform following steps till j not reaches to
length of string2
i) copy jth element of string2 in ith element of
string1.
ii) increment i and j by 1.
5. Store ‘0’ to ith element of string1.
void concate(char str1[],char str2[])
{
int i,j,len1,len2;
for(len1=0;str1[len1]!='0';len1++);
for(len2=0;str1[len2]!='0';len2++);
for(i=len1,j=0;j<len2;j++,i++)
{
str1[i]=str2[j];
}
str1[i]='0';
}
‘s’ ‘d’ ‘s’ ‘0’ blank blank blank
i
s
Convert t to
uppercase
‘s’ ‘d’ ‘s’ ‘0’ blank blank blank
i
S Convert t to
uppercase
s
‘S’ ‘d’ ‘s’ ‘0’ blank blank blank
i
D Convert t to
uppercase
d
‘S’ ‘D’ ‘s’ ‘0’ blank blank blank
i
S Convert t to
uppercase
s
‘S’ ‘D’ ‘S’ ‘0’ blank blank blank
i
1. Find length of string.
2. Initialize i = 0.
3. Perform following steps till i is not equal to length of string.
a) check whether ith element of string is lowercase or not.
i) if it is lowercase then subtract 32 from ASCII value.
b) increment i by 1.
void convert (char str[])
{
int i,len;
for(len=0;str[len]!='0';len++);
for(i=0; i< len; i++)
{
if(str[i]>=‘a’ && str[i]<=‘z’)
str[i]= str[i]-32;
}
}
Char name1[ ]=“SDSRK”,name2[ ] = “SDSKK”;
‘S’ ‘D’ ‘S’ ‘R’ ‘K’ ‘0’ blank
i
‘S’ ‘D’ ‘S’ ‘K’ ‘K’ ‘0’ blank
mismatch
1. Initialize i=0.
2. Perform following steps till any of the strings
get ‘0’
i) check ith element of both the strings.
ii) if they are not same then return the difference
of ASCII value
iii) else increase the value of i by 1.
3. If both strings are same, return 0.
int compare(char str1[],char str2[])
{
int i;
for(i=0;str1[i]!='0'||str2[i]!='0';i++)
{
if (str1[i]!=str2[i])
return (str1[i]-str2[i]);
}
return 0;
}
‘s’ ‘d’ ‘s’ ‘r’ ‘k’ ‘0’ blank
i
‘r’ ‘k’ ‘0’ blank blank blank
j
1. Find length of string1.
2. Find length of string2.
3. Initialize i = 0, j=0.
4. Perform following steps till i is less or equal to difference of
strings.
a) check whether ith element of string1 is equal to jth element of
string2.
b) if they are same then check other elements of string2 with
string1 untill length of string2
c) increment i by 1.
5. If substring is not found then return 0.
int substring(char str1[],char str2[])
{
int i,j,k,len1,len2;
for(len1=0;str1[len1]!='0';len1++);
for(len2=0;str2[len2]!='0';len2++);
for(i=0,j=0;i<=len1-len2;i++)
{ if (str1[i]==str2[j])
{
for(j=0,k=i;j<len2;k++,j++)
{ if(str1[k]!=str2[j])
return 0;
}
return i;
}
}
return 0;
}
‘m’ ‘i’ ‘n’ ‘i’ ‘m’ ‘0’
1. Find length of string.
2. Initialize i to 0 and j to length-1.
3. Perform following steps till i is less than half of string.
a) check whether ith element and jth element are same or not.
b) if not than return ASCII difference
c) increment i by 1 and decrement j by 1.
5. return 0.
int palindrome(char str[])
{
int i,j,len;
for(len=0;str[len]!='0';len++);
i=0;j=len;
while(i<len/2)
{
if(str[i]!=str[j])
return str[i]-str[j];
i++; j--;
}
return 0;
}
int palindrome(char str[]) {…………..}
void main()
{
char str[20];
int s;
clrscr();
gets(str);
s=palindrome(str);
printf("nString is %s palindrome.",(s==0)?("a"):(s));
getch();
}
HW
Write an algorithm and function that gives ascii difference of 2 characters.
Ie. String is ‘abcd’
Output:
a-b =ASCII (1)
b-c=ASCII (1)
c-d=ASCII (1)
String

More Related Content

Viewers also liked

Indian villages strength or weakness
Indian villages  strength or weaknessIndian villages  strength or weakness
Indian villages strength or weaknessBiswajit Patra
 
SWOT analysis of indian economy
SWOT analysis of indian economySWOT analysis of indian economy
SWOT analysis of indian economyAnkit Porwal
 
Indian villages Strength and weakness
Indian villages Strength and weaknessIndian villages Strength and weakness
Indian villages Strength and weaknessPrudhvi Thota
 
Proyecto de la universidad
Proyecto de la universidadProyecto de la universidad
Proyecto de la universidadJorge Solis
 
Enfermerdades degenerativas
Enfermerdades degenerativasEnfermerdades degenerativas
Enfermerdades degenerativasChechu Cooks
 
Educa Digital 2013
Educa Digital 2013Educa Digital 2013
Educa Digital 2013websocialcpe
 
ما هي الخلايا الجذعية السرطانية؟
ما هي الخلايا الجذعية  السرطانية؟ما هي الخلايا الجذعية  السرطانية؟
ما هي الخلايا الجذعية السرطانية؟Ghmkin Hsn
 
Presentación1
Presentación1Presentación1
Presentación1chafla106
 
áLbum de fotografías
áLbum de fotografíasáLbum de fotografías
áLbum de fotografíasshaggy0510
 
How to do a photo frame?
How to do a photo frame?How to do a photo frame?
How to do a photo frame?Rocío Delgado
 
Pierluca Santoro - InsPiRingPR 2014
Pierluca Santoro - InsPiRingPR 2014Pierluca Santoro - InsPiRingPR 2014
Pierluca Santoro - InsPiRingPR 2014InsPiRingPR
 
Ult apunt admon1
Ult apunt admon1Ult apunt admon1
Ult apunt admon1jessemx
 

Viewers also liked (20)

Indian villages strength or weakness
Indian villages  strength or weaknessIndian villages  strength or weakness
Indian villages strength or weakness
 
SWOT analysis of indian economy
SWOT analysis of indian economySWOT analysis of indian economy
SWOT analysis of indian economy
 
Reliance Fresh
Reliance FreshReliance Fresh
Reliance Fresh
 
Indian villages Strength and weakness
Indian villages Strength and weaknessIndian villages Strength and weakness
Indian villages Strength and weakness
 
Indian villages
Indian villagesIndian villages
Indian villages
 
Proyecto de la universidad
Proyecto de la universidadProyecto de la universidad
Proyecto de la universidad
 
Busqueda de datos
Busqueda de datosBusqueda de datos
Busqueda de datos
 
Alexandra
AlexandraAlexandra
Alexandra
 
Enfermerdades degenerativas
Enfermerdades degenerativasEnfermerdades degenerativas
Enfermerdades degenerativas
 
Educa Digital 2013
Educa Digital 2013Educa Digital 2013
Educa Digital 2013
 
ما هي الخلايا الجذعية السرطانية؟
ما هي الخلايا الجذعية  السرطانية؟ما هي الخلايا الجذعية  السرطانية؟
ما هي الخلايا الجذعية السرطانية؟
 
Presentación1
Presentación1Presentación1
Presentación1
 
Sapi potong
Sapi potongSapi potong
Sapi potong
 
Levensboek
LevensboekLevensboek
Levensboek
 
Busqueda de datos
Busqueda de datosBusqueda de datos
Busqueda de datos
 
Entrega diplomas 2013 14 virgen de la paz
Entrega diplomas 2013 14 virgen de la pazEntrega diplomas 2013 14 virgen de la paz
Entrega diplomas 2013 14 virgen de la paz
 
áLbum de fotografías
áLbum de fotografíasáLbum de fotografías
áLbum de fotografías
 
How to do a photo frame?
How to do a photo frame?How to do a photo frame?
How to do a photo frame?
 
Pierluca Santoro - InsPiRingPR 2014
Pierluca Santoro - InsPiRingPR 2014Pierluca Santoro - InsPiRingPR 2014
Pierluca Santoro - InsPiRingPR 2014
 
Ult apunt admon1
Ult apunt admon1Ult apunt admon1
Ult apunt admon1
 

Similar to String

CPSTRINGSARGAVISTRINGS.PPT
CPSTRINGSARGAVISTRINGS.PPTCPSTRINGSARGAVISTRINGS.PPT
CPSTRINGSARGAVISTRINGS.PPTSasideepa
 
BHARGAVISTRINGS.PPT
BHARGAVISTRINGS.PPTBHARGAVISTRINGS.PPT
BHARGAVISTRINGS.PPTSasideepa
 
INDIAN INSTITUTE OF TECHNOLOGY KANPURESC 111M Lec13.pptx
INDIAN INSTITUTE OF TECHNOLOGY KANPURESC 111M Lec13.pptxINDIAN INSTITUTE OF TECHNOLOGY KANPURESC 111M Lec13.pptx
INDIAN INSTITUTE OF TECHNOLOGY KANPURESC 111M Lec13.pptxAbhimanyuChaure
 
Module-2_Strings concepts in c programming
Module-2_Strings concepts in c programmingModule-2_Strings concepts in c programming
Module-2_Strings concepts in c programmingCHAITRAB29
 
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.pdfKirubelWondwoson1
 
13 Strings and text processing
13 Strings and text processing13 Strings and text processing
13 Strings and text processingmaznabili
 
fundamentals of c programming_String.pptx
fundamentals of c programming_String.pptxfundamentals of c programming_String.pptx
fundamentals of c programming_String.pptxJStalinAsstProfessor
 
Strings in c
Strings in cStrings in c
Strings in cvampugani
 
L13 string handling(string class)
L13 string handling(string class)L13 string handling(string class)
L13 string handling(string class)teach4uin
 
24_2-String and String Library.pptx
24_2-String and String Library.pptx24_2-String and String Library.pptx
24_2-String and String Library.pptxGandavadiVenkatesh1
 
Python Datatypes by SujithKumar
Python Datatypes by SujithKumarPython Datatypes by SujithKumar
Python Datatypes by SujithKumarSujith Kumar
 
C (PPS)Programming for problem solving.pptx
C (PPS)Programming for problem solving.pptxC (PPS)Programming for problem solving.pptx
C (PPS)Programming for problem solving.pptxrohinitalekar1
 

Similar to String (20)

CPSTRINGSARGAVISTRINGS.PPT
CPSTRINGSARGAVISTRINGS.PPTCPSTRINGSARGAVISTRINGS.PPT
CPSTRINGSARGAVISTRINGS.PPT
 
BHARGAVISTRINGS.PPT
BHARGAVISTRINGS.PPTBHARGAVISTRINGS.PPT
BHARGAVISTRINGS.PPT
 
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
 
INDIAN INSTITUTE OF TECHNOLOGY KANPURESC 111M Lec13.pptx
INDIAN INSTITUTE OF TECHNOLOGY KANPURESC 111M Lec13.pptxINDIAN INSTITUTE OF TECHNOLOGY KANPURESC 111M Lec13.pptx
INDIAN INSTITUTE OF TECHNOLOGY KANPURESC 111M Lec13.pptx
 
Module-2_Strings concepts in c programming
Module-2_Strings concepts in c programmingModule-2_Strings concepts in c programming
Module-2_Strings concepts in c programming
 
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
 
13 Strings and text processing
13 Strings and text processing13 Strings and text processing
13 Strings and text processing
 
fundamentals of c programming_String.pptx
fundamentals of c programming_String.pptxfundamentals of c programming_String.pptx
fundamentals of c programming_String.pptx
 
Strings in c
Strings in cStrings in c
Strings in c
 
2ds
2ds2ds
2ds
 
L13 string handling(string class)
L13 string handling(string class)L13 string handling(string class)
L13 string handling(string class)
 
24_2-String and String Library.pptx
24_2-String and String Library.pptx24_2-String and String Library.pptx
24_2-String and String Library.pptx
 
Strings part2
Strings part2Strings part2
Strings part2
 
Team 1
Team 1Team 1
Team 1
 
Java string handling
Java string handlingJava string handling
Java string handling
 
Python Datatypes by SujithKumar
Python Datatypes by SujithKumarPython Datatypes by SujithKumar
Python Datatypes by SujithKumar
 
Strings IN C
Strings IN CStrings IN C
Strings IN C
 
C (PPS)Programming for problem solving.pptx
C (PPS)Programming for problem solving.pptxC (PPS)Programming for problem solving.pptx
C (PPS)Programming for problem solving.pptx
 

Recently uploaded

Aspirational Block Program Block Syaldey District - Almora
Aspirational Block Program Block Syaldey District - AlmoraAspirational Block Program Block Syaldey District - Almora
Aspirational Block Program Block Syaldey District - AlmoraGovindSinghDasila
 
RESEARCH-FINAL-DEFENSE-PPT-TEMPLATE.pptx
RESEARCH-FINAL-DEFENSE-PPT-TEMPLATE.pptxRESEARCH-FINAL-DEFENSE-PPT-TEMPLATE.pptx
RESEARCH-FINAL-DEFENSE-PPT-TEMPLATE.pptxronsairoathenadugay
 
High Profile Call Girls Service in Jalore { 9332606886 } VVIP NISHA Call Girl...
High Profile Call Girls Service in Jalore { 9332606886 } VVIP NISHA Call Girl...High Profile Call Girls Service in Jalore { 9332606886 } VVIP NISHA Call Girl...
High Profile Call Girls Service in Jalore { 9332606886 } VVIP NISHA Call Girl...kumargunjan9515
 
Top profile Call Girls In dimapur [ 7014168258 ] Call Me For Genuine Models W...
Top profile Call Girls In dimapur [ 7014168258 ] Call Me For Genuine Models W...Top profile Call Girls In dimapur [ 7014168258 ] Call Me For Genuine Models W...
Top profile Call Girls In dimapur [ 7014168258 ] Call Me For Genuine Models W...gajnagarg
 
Sealdah % High Class Call Girls Kolkata - 450+ Call Girl Cash Payment 8005736...
Sealdah % High Class Call Girls Kolkata - 450+ Call Girl Cash Payment 8005736...Sealdah % High Class Call Girls Kolkata - 450+ Call Girl Cash Payment 8005736...
Sealdah % High Class Call Girls Kolkata - 450+ Call Girl Cash Payment 8005736...HyderabadDolls
 
如何办理英国诺森比亚大学毕业证(NU毕业证书)成绩单原件一模一样
如何办理英国诺森比亚大学毕业证(NU毕业证书)成绩单原件一模一样如何办理英国诺森比亚大学毕业证(NU毕业证书)成绩单原件一模一样
如何办理英国诺森比亚大学毕业证(NU毕业证书)成绩单原件一模一样wsppdmt
 
Sonagachi * best call girls in Kolkata | ₹,9500 Pay Cash 8005736733 Free Home...
Sonagachi * best call girls in Kolkata | ₹,9500 Pay Cash 8005736733 Free Home...Sonagachi * best call girls in Kolkata | ₹,9500 Pay Cash 8005736733 Free Home...
Sonagachi * best call girls in Kolkata | ₹,9500 Pay Cash 8005736733 Free Home...HyderabadDolls
 
Top profile Call Girls In Vadodara [ 7014168258 ] Call Me For Genuine Models ...
Top profile Call Girls In Vadodara [ 7014168258 ] Call Me For Genuine Models ...Top profile Call Girls In Vadodara [ 7014168258 ] Call Me For Genuine Models ...
Top profile Call Girls In Vadodara [ 7014168258 ] Call Me For Genuine Models ...gajnagarg
 
Gartner's Data Analytics Maturity Model.pptx
Gartner's Data Analytics Maturity Model.pptxGartner's Data Analytics Maturity Model.pptx
Gartner's Data Analytics Maturity Model.pptxchadhar227
 
Nirala Nagar / Cheap Call Girls In Lucknow Phone No 9548273370 Elite Escort S...
Nirala Nagar / Cheap Call Girls In Lucknow Phone No 9548273370 Elite Escort S...Nirala Nagar / Cheap Call Girls In Lucknow Phone No 9548273370 Elite Escort S...
Nirala Nagar / Cheap Call Girls In Lucknow Phone No 9548273370 Elite Escort S...HyderabadDolls
 
Digital Advertising Lecture for Advanced Digital & Social Media Strategy at U...
Digital Advertising Lecture for Advanced Digital & Social Media Strategy at U...Digital Advertising Lecture for Advanced Digital & Social Media Strategy at U...
Digital Advertising Lecture for Advanced Digital & Social Media Strategy at U...Valters Lauzums
 
Vadodara 💋 Call Girl 7737669865 Call Girls in Vadodara Escort service book now
Vadodara 💋 Call Girl 7737669865 Call Girls in Vadodara Escort service book nowVadodara 💋 Call Girl 7737669865 Call Girls in Vadodara Escort service book now
Vadodara 💋 Call Girl 7737669865 Call Girls in Vadodara Escort service book nowgargpaaro
 
Kings of Saudi Arabia, information about them
Kings of Saudi Arabia, information about themKings of Saudi Arabia, information about them
Kings of Saudi Arabia, information about themeitharjee
 
In Riyadh ((+919101817206)) Cytotec kit @ Abortion Pills Saudi Arabia
In Riyadh ((+919101817206)) Cytotec kit @ Abortion Pills Saudi ArabiaIn Riyadh ((+919101817206)) Cytotec kit @ Abortion Pills Saudi Arabia
In Riyadh ((+919101817206)) Cytotec kit @ Abortion Pills Saudi Arabiaahmedjiabur940
 
Charbagh + Female Escorts Service in Lucknow | Starting ₹,5K To @25k with A/C...
Charbagh + Female Escorts Service in Lucknow | Starting ₹,5K To @25k with A/C...Charbagh + Female Escorts Service in Lucknow | Starting ₹,5K To @25k with A/C...
Charbagh + Female Escorts Service in Lucknow | Starting ₹,5K To @25k with A/C...HyderabadDolls
 
Discover Why Less is More in B2B Research
Discover Why Less is More in B2B ResearchDiscover Why Less is More in B2B Research
Discover Why Less is More in B2B Researchmichael115558
 
Lecture_2_Deep_Learning_Overview-newone1
Lecture_2_Deep_Learning_Overview-newone1Lecture_2_Deep_Learning_Overview-newone1
Lecture_2_Deep_Learning_Overview-newone1ranjankumarbehera14
 
+97470301568>>weed for sale in qatar ,weed for sale in dubai,weed for sale in...
+97470301568>>weed for sale in qatar ,weed for sale in dubai,weed for sale in...+97470301568>>weed for sale in qatar ,weed for sale in dubai,weed for sale in...
+97470301568>>weed for sale in qatar ,weed for sale in dubai,weed for sale in...Health
 
Jual Obat Aborsi Surabaya ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Surabaya ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Surabaya ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Surabaya ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...ZurliaSoop
 
Top profile Call Girls In Bihar Sharif [ 7014168258 ] Call Me For Genuine Mod...
Top profile Call Girls In Bihar Sharif [ 7014168258 ] Call Me For Genuine Mod...Top profile Call Girls In Bihar Sharif [ 7014168258 ] Call Me For Genuine Mod...
Top profile Call Girls In Bihar Sharif [ 7014168258 ] Call Me For Genuine Mod...nirzagarg
 

Recently uploaded (20)

Aspirational Block Program Block Syaldey District - Almora
Aspirational Block Program Block Syaldey District - AlmoraAspirational Block Program Block Syaldey District - Almora
Aspirational Block Program Block Syaldey District - Almora
 
RESEARCH-FINAL-DEFENSE-PPT-TEMPLATE.pptx
RESEARCH-FINAL-DEFENSE-PPT-TEMPLATE.pptxRESEARCH-FINAL-DEFENSE-PPT-TEMPLATE.pptx
RESEARCH-FINAL-DEFENSE-PPT-TEMPLATE.pptx
 
High Profile Call Girls Service in Jalore { 9332606886 } VVIP NISHA Call Girl...
High Profile Call Girls Service in Jalore { 9332606886 } VVIP NISHA Call Girl...High Profile Call Girls Service in Jalore { 9332606886 } VVIP NISHA Call Girl...
High Profile Call Girls Service in Jalore { 9332606886 } VVIP NISHA Call Girl...
 
Top profile Call Girls In dimapur [ 7014168258 ] Call Me For Genuine Models W...
Top profile Call Girls In dimapur [ 7014168258 ] Call Me For Genuine Models W...Top profile Call Girls In dimapur [ 7014168258 ] Call Me For Genuine Models W...
Top profile Call Girls In dimapur [ 7014168258 ] Call Me For Genuine Models W...
 
Sealdah % High Class Call Girls Kolkata - 450+ Call Girl Cash Payment 8005736...
Sealdah % High Class Call Girls Kolkata - 450+ Call Girl Cash Payment 8005736...Sealdah % High Class Call Girls Kolkata - 450+ Call Girl Cash Payment 8005736...
Sealdah % High Class Call Girls Kolkata - 450+ Call Girl Cash Payment 8005736...
 
如何办理英国诺森比亚大学毕业证(NU毕业证书)成绩单原件一模一样
如何办理英国诺森比亚大学毕业证(NU毕业证书)成绩单原件一模一样如何办理英国诺森比亚大学毕业证(NU毕业证书)成绩单原件一模一样
如何办理英国诺森比亚大学毕业证(NU毕业证书)成绩单原件一模一样
 
Sonagachi * best call girls in Kolkata | ₹,9500 Pay Cash 8005736733 Free Home...
Sonagachi * best call girls in Kolkata | ₹,9500 Pay Cash 8005736733 Free Home...Sonagachi * best call girls in Kolkata | ₹,9500 Pay Cash 8005736733 Free Home...
Sonagachi * best call girls in Kolkata | ₹,9500 Pay Cash 8005736733 Free Home...
 
Top profile Call Girls In Vadodara [ 7014168258 ] Call Me For Genuine Models ...
Top profile Call Girls In Vadodara [ 7014168258 ] Call Me For Genuine Models ...Top profile Call Girls In Vadodara [ 7014168258 ] Call Me For Genuine Models ...
Top profile Call Girls In Vadodara [ 7014168258 ] Call Me For Genuine Models ...
 
Gartner's Data Analytics Maturity Model.pptx
Gartner's Data Analytics Maturity Model.pptxGartner's Data Analytics Maturity Model.pptx
Gartner's Data Analytics Maturity Model.pptx
 
Nirala Nagar / Cheap Call Girls In Lucknow Phone No 9548273370 Elite Escort S...
Nirala Nagar / Cheap Call Girls In Lucknow Phone No 9548273370 Elite Escort S...Nirala Nagar / Cheap Call Girls In Lucknow Phone No 9548273370 Elite Escort S...
Nirala Nagar / Cheap Call Girls In Lucknow Phone No 9548273370 Elite Escort S...
 
Digital Advertising Lecture for Advanced Digital & Social Media Strategy at U...
Digital Advertising Lecture for Advanced Digital & Social Media Strategy at U...Digital Advertising Lecture for Advanced Digital & Social Media Strategy at U...
Digital Advertising Lecture for Advanced Digital & Social Media Strategy at U...
 
Vadodara 💋 Call Girl 7737669865 Call Girls in Vadodara Escort service book now
Vadodara 💋 Call Girl 7737669865 Call Girls in Vadodara Escort service book nowVadodara 💋 Call Girl 7737669865 Call Girls in Vadodara Escort service book now
Vadodara 💋 Call Girl 7737669865 Call Girls in Vadodara Escort service book now
 
Kings of Saudi Arabia, information about them
Kings of Saudi Arabia, information about themKings of Saudi Arabia, information about them
Kings of Saudi Arabia, information about them
 
In Riyadh ((+919101817206)) Cytotec kit @ Abortion Pills Saudi Arabia
In Riyadh ((+919101817206)) Cytotec kit @ Abortion Pills Saudi ArabiaIn Riyadh ((+919101817206)) Cytotec kit @ Abortion Pills Saudi Arabia
In Riyadh ((+919101817206)) Cytotec kit @ Abortion Pills Saudi Arabia
 
Charbagh + Female Escorts Service in Lucknow | Starting ₹,5K To @25k with A/C...
Charbagh + Female Escorts Service in Lucknow | Starting ₹,5K To @25k with A/C...Charbagh + Female Escorts Service in Lucknow | Starting ₹,5K To @25k with A/C...
Charbagh + Female Escorts Service in Lucknow | Starting ₹,5K To @25k with A/C...
 
Discover Why Less is More in B2B Research
Discover Why Less is More in B2B ResearchDiscover Why Less is More in B2B Research
Discover Why Less is More in B2B Research
 
Lecture_2_Deep_Learning_Overview-newone1
Lecture_2_Deep_Learning_Overview-newone1Lecture_2_Deep_Learning_Overview-newone1
Lecture_2_Deep_Learning_Overview-newone1
 
+97470301568>>weed for sale in qatar ,weed for sale in dubai,weed for sale in...
+97470301568>>weed for sale in qatar ,weed for sale in dubai,weed for sale in...+97470301568>>weed for sale in qatar ,weed for sale in dubai,weed for sale in...
+97470301568>>weed for sale in qatar ,weed for sale in dubai,weed for sale in...
 
Jual Obat Aborsi Surabaya ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Surabaya ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Surabaya ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Surabaya ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
 
Top profile Call Girls In Bihar Sharif [ 7014168258 ] Call Me For Genuine Mod...
Top profile Call Girls In Bihar Sharif [ 7014168258 ] Call Me For Genuine Mod...Top profile Call Girls In Bihar Sharif [ 7014168258 ] Call Me For Genuine Mod...
Top profile Call Girls In Bihar Sharif [ 7014168258 ] Call Me For Genuine Mod...
 

String

  • 1. Chapter - 7 • Introduction • Representation of string • Operation on string
  • 2. • String is a primitive data structure. • It is represented as sequence of characters. •“hello” = ‘h’, ’e’, ’l’, ’l’, ’o’
  • 3. Define :- Char name[20]; // 1D array Here name is array of characters and treated as string. Size of name is 20
  • 4. Char name[20]=“SDS”; Char name[20]={‘S’, ’D’, ’S’,’0’}; ‘S’ ‘D’ ‘S’ ‘0’ blank blank
  • 5.
  • 6. Char name[ ]=“Diploma”; Size will be allocated 8 (string length+1) as ‘0’ will be counted.
  • 7.
  • 8. Char name[ ][ ]={“mahesh”, “suresh”, “mukesh”, “ramesh”}; ‘m’ ‘a’ ‘h’ ‘e’ ‘s’ ‘h’ ‘0’ ‘s’ ‘u’ ‘r’ ‘e’ s’ ‘h’ ‘0’ ‘m’ ‘u’ ‘k’ ‘e’ s’ ‘h’ ‘0’ ‘r’ ‘a’ ‘m’ ‘e’ s’ ‘h’ ‘0’
  • 9.
  • 10. Char name[20]=“SDS”; ‘S’ ‘D’ ‘S’ ‘0’ blank blank 1. Initialize len =0; 2. Perform following steps until len reaches to ‘0’ i) otherwise increment value of len by1. 3. return len. len
  • 11. int strlen(char str[]) { int len; for(len=0;str[len] !=‘0’;len++); return len; }
  • 12. int strlen(char str[]); void main() { int length; char name[20]; clrscr(); gets(name); length=strlen(name); printf("length is : %d",length); getch(); } int strlen(char str[]) { int len; for(len=0;str[len] !='0';len++); return len; }
  • 13. Char name[20]=“SDSRK”; ‘S’ ‘D’ ‘S’ ‘R’ ‘K’ ‘0’ blank i j
  • 14. ‘S’ ‘D’ ‘S’ ‘R’ ‘K’ ‘0’ blank i j s k Char name[20]=“SDSRK”;
  • 15. ‘K’ ‘D’ ‘S’ ‘r’ ‘S’ ‘0’ blank i j D R Char name[20]=“SDSRK”;
  • 16. ‘K’ ‘R’ ‘S’ ‘D’ ‘S’ ‘0’ blank ij 1. Find length of string 2. Initialize i=0 and j=length-1. 3. Perform following steps till i less than length/2 i) exchange the element at ith and jth position. ii) increment i by 1 iii) decrement j by 1 Char name[20]=“SDSRK”;
  • 17. void reverse(char str[]) { int i,j,len; char temp; for(len=0;str[len]!='0';len++); for(i=0,j=len-1;i<len/2;i++,j--) { temp=str[i]; str[i]=str[j]; str[j]=temp; } return; }
  • 18. ‘S’ ‘D’ ‘S’ ‘0’ blank blank blank ‘R’ ‘K’ ‘U’ ‘0’ blank blank i j R
  • 19. ‘S’ ‘D’ ‘S’ ‘R’ blank blank blank ‘R’ ‘K’ ‘U’ ‘0’ blank blank i j K
  • 20. ‘S’ ‘D’ ‘S’ ‘R’ ‘K’ blank blank ‘R’ ‘K’ ‘U’ ‘0’ blank blank i j U
  • 21. ‘S’ ‘D’ ‘S’ ‘R’ ‘K’ ‘U’ blank ‘R’ ‘K’ ‘U’ ‘0’ blank blank i j ‘0’
  • 22. ‘S’ ‘D’ ‘S’ ‘R’ ‘K’ ‘U’ ‘0’ blank ‘R’ ‘K’ ‘U’ ‘0’ blank blank i j
  • 23. 1. Find length of string1. 2. Find length of string2. 3. Initialize i=length of string1 and j to 0. 4. Perform following steps till j not reaches to length of string2 i) copy jth element of string2 in ith element of string1. ii) increment i and j by 1. 5. Store ‘0’ to ith element of string1.
  • 24. void concate(char str1[],char str2[]) { int i,j,len1,len2; for(len1=0;str1[len1]!='0';len1++); for(len2=0;str1[len2]!='0';len2++); for(i=len1,j=0;j<len2;j++,i++) { str1[i]=str2[j]; } str1[i]='0'; }
  • 25. ‘s’ ‘d’ ‘s’ ‘0’ blank blank blank i s Convert t to uppercase
  • 26. ‘s’ ‘d’ ‘s’ ‘0’ blank blank blank i S Convert t to uppercase s
  • 27. ‘S’ ‘d’ ‘s’ ‘0’ blank blank blank i D Convert t to uppercase d
  • 28. ‘S’ ‘D’ ‘s’ ‘0’ blank blank blank i S Convert t to uppercase s
  • 29. ‘S’ ‘D’ ‘S’ ‘0’ blank blank blank i
  • 30. 1. Find length of string. 2. Initialize i = 0. 3. Perform following steps till i is not equal to length of string. a) check whether ith element of string is lowercase or not. i) if it is lowercase then subtract 32 from ASCII value. b) increment i by 1.
  • 31. void convert (char str[]) { int i,len; for(len=0;str[len]!='0';len++); for(i=0; i< len; i++) { if(str[i]>=‘a’ && str[i]<=‘z’) str[i]= str[i]-32; } }
  • 32. Char name1[ ]=“SDSRK”,name2[ ] = “SDSKK”; ‘S’ ‘D’ ‘S’ ‘R’ ‘K’ ‘0’ blank i ‘S’ ‘D’ ‘S’ ‘K’ ‘K’ ‘0’ blank mismatch
  • 33. 1. Initialize i=0. 2. Perform following steps till any of the strings get ‘0’ i) check ith element of both the strings. ii) if they are not same then return the difference of ASCII value iii) else increase the value of i by 1. 3. If both strings are same, return 0.
  • 34. int compare(char str1[],char str2[]) { int i; for(i=0;str1[i]!='0'||str2[i]!='0';i++) { if (str1[i]!=str2[i]) return (str1[i]-str2[i]); } return 0; }
  • 35. ‘s’ ‘d’ ‘s’ ‘r’ ‘k’ ‘0’ blank i ‘r’ ‘k’ ‘0’ blank blank blank j
  • 36. 1. Find length of string1. 2. Find length of string2. 3. Initialize i = 0, j=0. 4. Perform following steps till i is less or equal to difference of strings. a) check whether ith element of string1 is equal to jth element of string2. b) if they are same then check other elements of string2 with string1 untill length of string2 c) increment i by 1. 5. If substring is not found then return 0.
  • 37. int substring(char str1[],char str2[]) { int i,j,k,len1,len2; for(len1=0;str1[len1]!='0';len1++); for(len2=0;str2[len2]!='0';len2++); for(i=0,j=0;i<=len1-len2;i++) { if (str1[i]==str2[j]) { for(j=0,k=i;j<len2;k++,j++) { if(str1[k]!=str2[j]) return 0; } return i; } } return 0; }
  • 38. ‘m’ ‘i’ ‘n’ ‘i’ ‘m’ ‘0’
  • 39. 1. Find length of string. 2. Initialize i to 0 and j to length-1. 3. Perform following steps till i is less than half of string. a) check whether ith element and jth element are same or not. b) if not than return ASCII difference c) increment i by 1 and decrement j by 1. 5. return 0.
  • 40. int palindrome(char str[]) { int i,j,len; for(len=0;str[len]!='0';len++); i=0;j=len; while(i<len/2) { if(str[i]!=str[j]) return str[i]-str[j]; i++; j--; } return 0; }
  • 41. int palindrome(char str[]) {…………..} void main() { char str[20]; int s; clrscr(); gets(str); s=palindrome(str); printf("nString is %s palindrome.",(s==0)?("a"):(s)); getch(); }
  • 42. HW Write an algorithm and function that gives ascii difference of 2 characters. Ie. String is ‘abcd’ Output: a-b =ASCII (1) b-c=ASCII (1) c-d=ASCII (1)