Advertisement
Guest User

Untitled

a guest
Sep 30th, 2014
178
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.42 KB | None | 0 0
  1. typedef struct{
  2.   string name;
  3.   const void * file;
  4. }plr;
  5.  
  6. void printing(void * vp){
  7.   int count=0;
  8.   while(*((char*)vp+count)!='\0'){
  9.     cout<<*((char*)vp+count);
  10.     count++;
  11.   }
  12.   cout << endl;
  13. }
  14.  
  15. int compar(const void* vp1,const void* vp2){
  16.   plr temp= *(plr*)vp1;
  17.   string first = temp.name;
  18.   char * forFirst = &first[0];
  19.   char *second = ((char*)temp.file+*(int*)vp2);
  20.   return strcmp(forFirst,second);
  21. }
  22.  
  23. int count(void * base){
  24.   int count =0;
  25.   while(*((char*)base+count)!='\0'){
  26.     count++;
  27.   }
  28.   int next=0;
  29.   while(*((char*)base+count+next)=='\0'){
  30.     next++;
  31.   }
  32.   return count+next;
  33. }
  34.  
  35.  
  36. void * adress(void * base){
  37.   int count =0;
  38.   while(*((char*)base+count)!='\0'){
  39.     count++;
  40.   }
  41.   int next=0;
  42.   while(*((char*)base+count+next)=='\0'){
  43.     next++;
  44.   }
  45.   return (char*)base+count+next;
  46. }
  47. string getString(void *start,void *end){
  48.   int count =0;
  49.   string res="";
  50.   while(start != end){
  51.     if(*((char*)start+count) != '\0')
  52.       res += *((char*)start+count);
  53.     count++;
  54.   }
  55.   return res;
  56. }
  57.  
  58.  
  59.  
  60. // you should be implementing these two methods right here...
  61. bool imdb::getCredits(const string& player, vector<film>& films) const {
  62.   plr str;
  63.   str.name = player;
  64.   str.file = actorFile;
  65.   void * actor = bsearch(&str,(char*)actorFile+sizeof(int),*(int*)actorFile,sizeof(int),compar);
  66.   if(bsearch(&str,(char*)actorFile+sizeof(int),*(int*)actorFile,sizeof(int),compar) == NULL)
  67.     return false;
  68.   printing((char*) actorFile + *(int*)actor);
  69.   char * temp = (char*)actorFile+*(int*)actor;
  70.   short numMovies = *(short*)adress(temp);
  71.   printf("%d\n",numMovies);
  72.   for(short i=0; i<numMovies;i++){
  73.     //    printf("%d",count(temp)+count(adress(temp)));
  74.     if((count(temp)+count(adress(temp)))%4==0){
  75.       int movie = *((char*)adress(temp)+i*sizeof(int)+2);
  76.       printf("%d\n",movie);
  77.       //     char * movieName = ((char*)movieFile+movie);
  78.       //  printing(movieName);
  79.     } else {
  80.       int movie = *((char*)adress(temp)+4+i*sizeof(int));
  81.       printf("%d\n",movie);
  82.       //     char * movieName = ((char*)movieFile+movie);
  83.       //     printing(movieName);
  84.     }
  85.     /*
  86.     string name = getString(movieName,(char*)adress(movieName));
  87.     char year = *(char*)(adress(movieName));
  88.     int publicYear = 1900+year;
  89.     film addMovie;
  90.     addMovie.title = name;
  91.     addMovie.year = publicYear;
  92.     films.push_back(addMovie);
  93.     */
  94.   }
  95.  
  96.  return true;
  97.  }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement