Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- typedef struct{
- string name;
- const void * file;
- }plr;
- void printing(void * vp){
- int count=0;
- while(*((char*)vp+count)!='\0'){
- cout<<*((char*)vp+count);
- count++;
- }
- cout << endl;
- }
- int compar(const void* vp1,const void* vp2){
- plr temp= *(plr*)vp1;
- string first = temp.name;
- char * forFirst = &first[0];
- char *second = ((char*)temp.file+*(int*)vp2);
- return strcmp(forFirst,second);
- }
- int count(void * base){
- int count =0;
- while(*((char*)base+count)!='\0'){
- count++;
- }
- int next=0;
- while(*((char*)base+count+next)=='\0'){
- next++;
- }
- return count+next;
- }
- void * adress(void * base){
- int count =0;
- while(*((char*)base+count)!='\0'){
- count++;
- }
- int next=0;
- while(*((char*)base+count+next)=='\0'){
- next++;
- }
- return (char*)base+count+next;
- }
- string getString(void *start,void *end){
- int count =0;
- string res="";
- while(start != end){
- if(*((char*)start+count) != '\0')
- res += *((char*)start+count);
- count++;
- }
- return res;
- }
- // you should be implementing these two methods right here...
- bool imdb::getCredits(const string& player, vector<film>& films) const {
- plr str;
- str.name = player;
- str.file = actorFile;
- void * actor = bsearch(&str,(char*)actorFile+sizeof(int),*(int*)actorFile,sizeof(int),compar);
- if(bsearch(&str,(char*)actorFile+sizeof(int),*(int*)actorFile,sizeof(int),compar) == NULL)
- return false;
- printing((char*) actorFile + *(int*)actor);
- char * temp = (char*)actorFile+*(int*)actor;
- short numMovies = *(short*)adress(temp);
- printf("%d\n",numMovies);
- for(short i=0; i<numMovies;i++){
- // printf("%d",count(temp)+count(adress(temp)));
- if((count(temp)+count(adress(temp)))%4==0){
- int movie = *((char*)adress(temp)+i*sizeof(int)+2);
- printf("%d\n",movie);
- // char * movieName = ((char*)movieFile+movie);
- // printing(movieName);
- } else {
- int movie = *((char*)adress(temp)+4+i*sizeof(int));
- printf("%d\n",movie);
- // char * movieName = ((char*)movieFile+movie);
- // printing(movieName);
- }
- /*
- string name = getString(movieName,(char*)adress(movieName));
- char year = *(char*)(adress(movieName));
- int publicYear = 1900+year;
- film addMovie;
- addMovie.title = name;
- addMovie.year = publicYear;
- films.push_back(addMovie);
- */
- }
- return true;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement