1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95
|
#include <iostream>
#include <string.h>
#include <fstream>
using namespace std;
class client
{
char *code;
char *name,*surname;
char *tel;
char *adr;
char *city;
char *country;
public:
void substract(char *);
};
void client::substract(char *cline)
{
char *pch = strtok (cline," ");
code=strtok(NULL," ");
cout<<code;
strtok(NULL," ");
pch = strtok (NULL," ");
while(strcmpi(pch,"<surname>"))
{
strcat(name,pch);
strcat(name," ");
pch = strtok (NULL," ");
}
cout<<name; //somewhere here is the problem
pch = strtok (NULL," ");
while(strcmpi(pch,"<tel>")!=0)
{
strcat(surname,pch);
strcat(surname," ");
pch = strtok (NULL," ");
}
cout<<surname;
pch = strtok (NULL," ");
while(strcmpi(pch,"<adress>")!=0)
{
strcat(tel,pch);
strcat(tel," ");
pch = strtok (NULL," ");
}
cout<<tel;
pch = strtok (NULL," ");
while(strcmpi(pch,"<city>")!=0)
{
strcat(adr,pch);
strcat(adr," ");
pch = strtok (NULL," ");
}
pch = strtok (NULL," ");
while(strcmpi(pch,"<county>")!=0)
{
strcat(city,pch);
strcat(city," ");
pch = strtok (NULL," ");
}
pch = strtok (NULL," ");
while (pch != NULL)
{
strcat(country,pch);
strcat(country,pch);
}
}
int main()
{
ifstream book("phone_book_dtb.txt");
ifstream last_code("code.txt");
string line;
int lcode;
last_code>>lcode;
bool ok=false;
char par[10]="code";
string scr;
cin>>scr;
int x=scr.length() + 1;
char *src = new char[x];
strcpy(src, scr.c_str());
getline(book,line);
int n=line.length() + 1;
char *aux = new char[n];
strcpy(aux, line.c_str());
client c;
c.substract(aux);
return 0;
}
|