This code I am trying to right is for the Attribute parser question for the C++ program on Hackerrank. The code is not complete yet as I am passing into this dreadful infinite loop again and again as im not able to solve it.
The code:
struct tag{
char name[100];
char att[100][100];
char val[100][100];
};
int main(){
tag tags[100];
char line[200];
int n,q;
cin>>n>>q;
int a,b,c,flag;
a=0;
for(int i=0;i<n;i++){
cin.getline(line,200);
b=c=flag=0;
int j;
if(flag==0){
for(j=1;line[j]!=' '||line[j]!='>';j++)
{tags[a].name[j]=line[j];
cout<<"!";
}
flag=1;
}
else if(flag==1){
while(line[j]!='>'){
for(j+=1,c=0;line[j]!=' '||line[j]!='=';j++,c++){
tags[a].att[b][c]=line[j];
}
while(line[j]!='"')
j++;
for(j+=1,c=0;line[j]!='\"';j++,c++){
tags[a].val[b][c]=line[j];
}
b++;
}
a++;
}
}
cout<< tags[0].name[0];
return 0;
}
Also, I'm new to Coding and all. Constructive Criticism will be appreciated :))
Aucun commentaire:
Enregistrer un commentaire