Пример #1
0
int main(void)
{
  Family *first = NULL;                // Pointer to first person      
  Family *current = NULL;              // Pointer to current person    
  Family *last = NULL;                 // Pointer to previous person   
  char more = '\0';                    // Test value for ending input  

  while(true)
  {
    printf_s("\nDo you want to enter details of a%s person (Y or N)? ",
                                        first != NULL?"nother" : "");
    scanf_s(" %c", &more, sizeof(more));
    if(tolower(more) == 'n')
      break;

    current = get_person();

    if(first == NULL)
    {
      first = current;                // Set pointer to first Family  
      last = current;                 // Remember for next iteration  
    }
    else
    {
      last->next = current;   // Set next address for previous Family 
      current->previous = last;   // Set previous address for current 
      last = current;             // Remember for next iteration      
    }
  }

  show_people(true, first, last); // Tell them what we know 
  release_memory(first);
  first = last = NULL;
  return 0;
}
Пример #2
0
int application_request(int fd,data_person * users,int * newid)
{
    binary_semaphore_wait(semaphore);
    person person;
    simple_person * simple_person;
    int ans=0;
    clsvbuff buff;

    if(read_msg(fd,&buff)<0)
      return -1;

    switch(buff.opc)
    {
      case GET_INFO:
          ans = get_info(&buff,users,newid,&person);
          ans_get_info(fd,&buff,ans,&person);
          break;
      case GET_MATCHS:
          ans = get_matchs(&buff,users,&simple_person);
          ans_get_matchs(fd,ans,&buff,&simple_person);
          break;
      case SHOW_PEOPLE:
          ans = show_people(&buff,users,newid,&simple_person);
          ans_show_people(fd,ans,&buff,&simple_person);
          break;
      case REGISTER:
          ans=register_user(&buff,users,newid);
          ans_register_user(fd,ans,&buff);
          break;
      case LOGIN: /*In this case ans doubles as opOK*/
          ans = login(&buff,users,newid);
          ans_login(fd,ans,&buff);
          break;
      case EVALUATION:  /*In this case ans doubles as opOK*/
          users[buff.id_client-1].last_evaluation=buff.data.clsv_evaluation.id;
          if(buff.data.clsv_evaluation.like==true)
          {
            ans = evaluation(&buff,users);
            ans_evaluation(fd,ans,&buff);
          }
          else
           ans_evaluation(fd,0,&buff);

          break;
      default: /*OPC NOT RECOGNIZED*/
          return -1;
        break;
    }

    binary_semaphore_post(semaphore);



    return 0;

}