SlideShare a Scribd company logo
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 weakness
Biswajit Patra
 
SWOT analysis of indian economy
SWOT analysis of indian economySWOT analysis of indian economy
SWOT analysis of indian economy
Ankit Porwal
 
Reliance Fresh
Reliance FreshReliance Fresh
Reliance Fresh
anandganpaa
 
Indian villages Strength and weakness
Indian villages Strength and weaknessIndian villages Strength and weakness
Indian villages Strength and weakness
Prudhvi Thota
 
Indian villages
Indian villagesIndian villages
Indian villages
Sriteja Rst
 
Proyecto de la universidad
Proyecto de la universidadProyecto de la universidad
Proyecto de la universidad
Jorge Solis
 
Busqueda de datos
Busqueda de datosBusqueda de datos
Busqueda de datos
Kevin Jimenez
 
Alexandra
AlexandraAlexandra
Enfermerdades degenerativas
Enfermerdades degenerativasEnfermerdades degenerativas
Enfermerdades degenerativas
Chechu Cooks
 
Educa Digital 2013
Educa Digital 2013Educa Digital 2013
Educa Digital 2013
websocialcpe
 
ما هي الخلايا الجذعية السرطانية؟
ما هي الخلايا الجذعية  السرطانية؟ما هي الخلايا الجذعية  السرطانية؟
ما هي الخلايا الجذعية السرطانية؟
Ghmkin Hsn
 
Presentación1
Presentación1Presentación1
Presentación1
chafla106
 
Sapi potong
Sapi potongSapi potong
Sapi potong
Ahmad Sehah
 
Levensboek
LevensboekLevensboek
Levensboek
Silvia Philippi
 
Busqueda de datos
Busqueda de datosBusqueda de datos
Busqueda de datos
Kevin Jimenez
 
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
Parque Infantil De Tráfico de Vícar
 
á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 2014
InsPiRingPR
 
Ult apunt admon1
Ult apunt admon1Ult apunt admon1
Ult apunt admon1
jessemx
 

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.PPT
Sasideepa
 
BHARGAVISTRINGS.PPT
BHARGAVISTRINGS.PPTBHARGAVISTRINGS.PPT
BHARGAVISTRINGS.PPT
Sasideepa
 
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
arunatluri
 
CP-STRING.ppt
CP-STRING.pptCP-STRING.ppt
CP-STRING.ppt
TAPANDDRAW
 
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
AbhimanyuChaure
 
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
CHAITRAB29
 
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
KirubelWondwoson1
 
13 Strings and text processing
13 Strings and text processing13 Strings and text processing
13 Strings and text processing
maznabili
 
fundamentals of c programming_String.pptx
fundamentals of c programming_String.pptxfundamentals of c programming_String.pptx
fundamentals of c programming_String.pptx
JStalinAsstProfessor
 
Strings in c
Strings in cStrings in c
Strings in c
vampugani
 
2ds
2ds2ds
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.pptx
GandavadiVenkatesh1
 
Strings part2
Strings part2Strings part2
Strings part2
yndaravind
 
Team 1
Team 1Team 1
Java string handling
Java string handlingJava string handling
Java string handling
GaneshKumarKanthiah
 
Python Datatypes by SujithKumar
Python Datatypes by SujithKumarPython Datatypes by SujithKumar
Python Datatypes by SujithKumar
Sujith Kumar
 
Strings IN C
Strings IN CStrings IN C
Strings IN C
yndaravind
 
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
rohinitalekar1
 

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

一比一原版(UCSB文凭证书)圣芭芭拉分校毕业证如何办理
一比一原版(UCSB文凭证书)圣芭芭拉分校毕业证如何办理一比一原版(UCSB文凭证书)圣芭芭拉分校毕业证如何办理
一比一原版(UCSB文凭证书)圣芭芭拉分校毕业证如何办理
nuttdpt
 
一比一原版(UCSF文凭证书)旧金山分校毕业证如何办理
一比一原版(UCSF文凭证书)旧金山分校毕业证如何办理一比一原版(UCSF文凭证书)旧金山分校毕业证如何办理
一比一原版(UCSF文凭证书)旧金山分校毕业证如何办理
nuttdpt
 
一比一原版(爱大毕业证书)爱丁堡大学毕业证如何办理
一比一原版(爱大毕业证书)爱丁堡大学毕业证如何办理一比一原版(爱大毕业证书)爱丁堡大学毕业证如何办理
一比一原版(爱大毕业证书)爱丁堡大学毕业证如何办理
g4dpvqap0
 
在线办理(英国UCA毕业证书)创意艺术大学毕业证在读证明一模一样
在线办理(英国UCA毕业证书)创意艺术大学毕业证在读证明一模一样在线办理(英国UCA毕业证书)创意艺术大学毕业证在读证明一模一样
在线办理(英国UCA毕业证书)创意艺术大学毕业证在读证明一模一样
v7oacc3l
 
06-04-2024 - NYC Tech Week - Discussion on Vector Databases, Unstructured Dat...
06-04-2024 - NYC Tech Week - Discussion on Vector Databases, Unstructured Dat...06-04-2024 - NYC Tech Week - Discussion on Vector Databases, Unstructured Dat...
06-04-2024 - NYC Tech Week - Discussion on Vector Databases, Unstructured Dat...
Timothy Spann
 
06-12-2024-BudapestDataForum-BuildingReal-timePipelineswithFLaNK AIM
06-12-2024-BudapestDataForum-BuildingReal-timePipelineswithFLaNK AIM06-12-2024-BudapestDataForum-BuildingReal-timePipelineswithFLaNK AIM
06-12-2024-BudapestDataForum-BuildingReal-timePipelineswithFLaNK AIM
Timothy Spann
 
DSSML24_tspann_CodelessGenerativeAIPipelines
DSSML24_tspann_CodelessGenerativeAIPipelinesDSSML24_tspann_CodelessGenerativeAIPipelines
DSSML24_tspann_CodelessGenerativeAIPipelines
Timothy Spann
 
End-to-end pipeline agility - Berlin Buzzwords 2024
End-to-end pipeline agility - Berlin Buzzwords 2024End-to-end pipeline agility - Berlin Buzzwords 2024
End-to-end pipeline agility - Berlin Buzzwords 2024
Lars Albertsson
 
一比一原版(牛布毕业证书)牛津布鲁克斯大学毕业证如何办理
一比一原版(牛布毕业证书)牛津布鲁克斯大学毕业证如何办理一比一原版(牛布毕业证书)牛津布鲁克斯大学毕业证如何办理
一比一原版(牛布毕业证书)牛津布鲁克斯大学毕业证如何办理
74nqk8xf
 
ViewShift: Hassle-free Dynamic Policy Enforcement for Every Data Lake
ViewShift: Hassle-free Dynamic Policy Enforcement for Every Data LakeViewShift: Hassle-free Dynamic Policy Enforcement for Every Data Lake
ViewShift: Hassle-free Dynamic Policy Enforcement for Every Data Lake
Walaa Eldin Moustafa
 
Experts live - Improving user adoption with AI
Experts live - Improving user adoption with AIExperts live - Improving user adoption with AI
Experts live - Improving user adoption with AI
jitskeb
 
一比一原版(Harvard毕业证书)哈佛大学毕业证如何办理
一比一原版(Harvard毕业证书)哈佛大学毕业证如何办理一比一原版(Harvard毕业证书)哈佛大学毕业证如何办理
一比一原版(Harvard毕业证书)哈佛大学毕业证如何办理
zsjl4mimo
 
Analysis insight about a Flyball dog competition team's performance
Analysis insight about a Flyball dog competition team's performanceAnalysis insight about a Flyball dog competition team's performance
Analysis insight about a Flyball dog competition team's performance
roli9797
 
University of New South Wales degree offer diploma Transcript
University of New South Wales degree offer diploma TranscriptUniversity of New South Wales degree offer diploma Transcript
University of New South Wales degree offer diploma Transcript
soxrziqu
 
一比一原版(GWU,GW文凭证书)乔治·华盛顿大学毕业证如何办理
一比一原版(GWU,GW文凭证书)乔治·华盛顿大学毕业证如何办理一比一原版(GWU,GW文凭证书)乔治·华盛顿大学毕业证如何办理
一比一原版(GWU,GW文凭证书)乔治·华盛顿大学毕业证如何办理
bopyb
 
Global Situational Awareness of A.I. and where its headed
Global Situational Awareness of A.I. and where its headedGlobal Situational Awareness of A.I. and where its headed
Global Situational Awareness of A.I. and where its headed
vikram sood
 
一比一原版(Chester毕业证书)切斯特大学毕业证如何办理
一比一原版(Chester毕业证书)切斯特大学毕业证如何办理一比一原版(Chester毕业证书)切斯特大学毕业证如何办理
一比一原版(Chester毕业证书)切斯特大学毕业证如何办理
74nqk8xf
 
一比一原版(UO毕业证)渥太华大学毕业证如何办理
一比一原版(UO毕业证)渥太华大学毕业证如何办理一比一原版(UO毕业证)渥太华大学毕业证如何办理
一比一原版(UO毕业证)渥太华大学毕业证如何办理
aqzctr7x
 
Palo Alto Cortex XDR presentation .......
Palo Alto Cortex XDR presentation .......Palo Alto Cortex XDR presentation .......
Palo Alto Cortex XDR presentation .......
Sachin Paul
 
Population Growth in Bataan: The effects of population growth around rural pl...
Population Growth in Bataan: The effects of population growth around rural pl...Population Growth in Bataan: The effects of population growth around rural pl...
Population Growth in Bataan: The effects of population growth around rural pl...
Bill641377
 

Recently uploaded (20)

一比一原版(UCSB文凭证书)圣芭芭拉分校毕业证如何办理
一比一原版(UCSB文凭证书)圣芭芭拉分校毕业证如何办理一比一原版(UCSB文凭证书)圣芭芭拉分校毕业证如何办理
一比一原版(UCSB文凭证书)圣芭芭拉分校毕业证如何办理
 
一比一原版(UCSF文凭证书)旧金山分校毕业证如何办理
一比一原版(UCSF文凭证书)旧金山分校毕业证如何办理一比一原版(UCSF文凭证书)旧金山分校毕业证如何办理
一比一原版(UCSF文凭证书)旧金山分校毕业证如何办理
 
一比一原版(爱大毕业证书)爱丁堡大学毕业证如何办理
一比一原版(爱大毕业证书)爱丁堡大学毕业证如何办理一比一原版(爱大毕业证书)爱丁堡大学毕业证如何办理
一比一原版(爱大毕业证书)爱丁堡大学毕业证如何办理
 
在线办理(英国UCA毕业证书)创意艺术大学毕业证在读证明一模一样
在线办理(英国UCA毕业证书)创意艺术大学毕业证在读证明一模一样在线办理(英国UCA毕业证书)创意艺术大学毕业证在读证明一模一样
在线办理(英国UCA毕业证书)创意艺术大学毕业证在读证明一模一样
 
06-04-2024 - NYC Tech Week - Discussion on Vector Databases, Unstructured Dat...
06-04-2024 - NYC Tech Week - Discussion on Vector Databases, Unstructured Dat...06-04-2024 - NYC Tech Week - Discussion on Vector Databases, Unstructured Dat...
06-04-2024 - NYC Tech Week - Discussion on Vector Databases, Unstructured Dat...
 
06-12-2024-BudapestDataForum-BuildingReal-timePipelineswithFLaNK AIM
06-12-2024-BudapestDataForum-BuildingReal-timePipelineswithFLaNK AIM06-12-2024-BudapestDataForum-BuildingReal-timePipelineswithFLaNK AIM
06-12-2024-BudapestDataForum-BuildingReal-timePipelineswithFLaNK AIM
 
DSSML24_tspann_CodelessGenerativeAIPipelines
DSSML24_tspann_CodelessGenerativeAIPipelinesDSSML24_tspann_CodelessGenerativeAIPipelines
DSSML24_tspann_CodelessGenerativeAIPipelines
 
End-to-end pipeline agility - Berlin Buzzwords 2024
End-to-end pipeline agility - Berlin Buzzwords 2024End-to-end pipeline agility - Berlin Buzzwords 2024
End-to-end pipeline agility - Berlin Buzzwords 2024
 
一比一原版(牛布毕业证书)牛津布鲁克斯大学毕业证如何办理
一比一原版(牛布毕业证书)牛津布鲁克斯大学毕业证如何办理一比一原版(牛布毕业证书)牛津布鲁克斯大学毕业证如何办理
一比一原版(牛布毕业证书)牛津布鲁克斯大学毕业证如何办理
 
ViewShift: Hassle-free Dynamic Policy Enforcement for Every Data Lake
ViewShift: Hassle-free Dynamic Policy Enforcement for Every Data LakeViewShift: Hassle-free Dynamic Policy Enforcement for Every Data Lake
ViewShift: Hassle-free Dynamic Policy Enforcement for Every Data Lake
 
Experts live - Improving user adoption with AI
Experts live - Improving user adoption with AIExperts live - Improving user adoption with AI
Experts live - Improving user adoption with AI
 
一比一原版(Harvard毕业证书)哈佛大学毕业证如何办理
一比一原版(Harvard毕业证书)哈佛大学毕业证如何办理一比一原版(Harvard毕业证书)哈佛大学毕业证如何办理
一比一原版(Harvard毕业证书)哈佛大学毕业证如何办理
 
Analysis insight about a Flyball dog competition team's performance
Analysis insight about a Flyball dog competition team's performanceAnalysis insight about a Flyball dog competition team's performance
Analysis insight about a Flyball dog competition team's performance
 
University of New South Wales degree offer diploma Transcript
University of New South Wales degree offer diploma TranscriptUniversity of New South Wales degree offer diploma Transcript
University of New South Wales degree offer diploma Transcript
 
一比一原版(GWU,GW文凭证书)乔治·华盛顿大学毕业证如何办理
一比一原版(GWU,GW文凭证书)乔治·华盛顿大学毕业证如何办理一比一原版(GWU,GW文凭证书)乔治·华盛顿大学毕业证如何办理
一比一原版(GWU,GW文凭证书)乔治·华盛顿大学毕业证如何办理
 
Global Situational Awareness of A.I. and where its headed
Global Situational Awareness of A.I. and where its headedGlobal Situational Awareness of A.I. and where its headed
Global Situational Awareness of A.I. and where its headed
 
一比一原版(Chester毕业证书)切斯特大学毕业证如何办理
一比一原版(Chester毕业证书)切斯特大学毕业证如何办理一比一原版(Chester毕业证书)切斯特大学毕业证如何办理
一比一原版(Chester毕业证书)切斯特大学毕业证如何办理
 
一比一原版(UO毕业证)渥太华大学毕业证如何办理
一比一原版(UO毕业证)渥太华大学毕业证如何办理一比一原版(UO毕业证)渥太华大学毕业证如何办理
一比一原版(UO毕业证)渥太华大学毕业证如何办理
 
Palo Alto Cortex XDR presentation .......
Palo Alto Cortex XDR presentation .......Palo Alto Cortex XDR presentation .......
Palo Alto Cortex XDR presentation .......
 
Population Growth in Bataan: The effects of population growth around rural pl...
Population Growth in Bataan: The effects of population growth around rural pl...Population Growth in Bataan: The effects of population growth around rural pl...
Population Growth in Bataan: The effects of population growth around rural pl...
 

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)