Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- int extrageCuvant(char d[],char s[],char sep[],int nc)
- {
- int Ls=0;
- while(s[Ls]!='\0') ++Ls; /// Calculez lungimea sirului sursa Ls
- int Lsep=0;
- while(sep[Lsep]!='\0') ++Lsep; /// Calculez lungimea sirului de separatori Lsep
- int i=0,Ld=0; /// Ld = lungimea sirului destinatie (cuvantul gasit)
- bool ok=true; /// daca se va gasi un separator, atunci ok=true
- while(ok)
- {
- ok=false;
- for(int j=0;j<Lsep;++j)
- if(s[i]==sep[j])
- {
- ok=true;
- ++i;
- break;
- }
- }
- int nrc=0; /// nrc = numarul cuvantului gasit
- while(i<Ls)
- {
- ok=false;
- for(int j=0;j<Lsep&&!ok;++j)
- if(s[i]==sep[j])
- ok=true;
- if(ok) /// Daca am ajuns la un separator (deci am gasit un cuvant)
- {
- d[Ld]='\0'; /// g<<nrc<<' '<<d<<endl;
- if(nrc==nc) /// Daca am ajuns la cuvantul cautat
- return 1;
- ++i; /// Trec la urmatorul caracter
- ok=true; /// ca sa trecem peste ceilalti separatori (daca sunt mai multi intre cuvinte)
- while(ok)
- {
- ok=false;
- for(int j=0;j<Lsep;++j)
- if(s[i]==sep[j])
- {
- ok=true;
- ++i;
- break;
- }
- }
- Ld=0; /// Caut un nou cuvant
- ++nrc;
- }
- d[Ld++]=s[i++];
- }
- ok=false;
- for(int j=0;j<Lsep;++j)
- if(s[Ls-1]==sep[j])
- {
- ok=true;
- break;
- }
- /// g<<"NRC="<<nrc<<endl;
- if(!ok&&nc==nrc)
- return 1;
- d[0]=0;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement