Facebook
From Bulky Monkey, 2 Years ago, written in Plain Text.
Embed
Download Paste or View Raw
Hits: 45
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4. /* run this program using the console pauser or add your own getch, system("pause") or input loop */
  5. struct Cage {
  6.         char type[10];
  7.         int age;
  8.         char id[10];
  9. };
  10.  
  11. struct QueueNode{
  12.         struct Cage node;
  13.         struct QueueNode *next;
  14. };
  15. void load_newcomers(struct QueueNode *root){
  16.  
  17.         struct QueueNode *res_root = root;
  18.         struct QueueNode *end_item = NULL;
  19.         FILE f;int sizeType=0,sizeId=0;
  20.         if((f=fopen("newcomers.bin", "rb"))==NULL){
  21.                 perror("Cant open file");
  22.                 return NULL;
  23.         }
  24.         while(!feof(f)){
  25.         struct QueueNode * item;
  26.         item= (QueueNode*)malloc(sizeof(QueueNode));
  27.        
  28.         fread(&sizeType, sizeof(int), 1, f);
  29.         fread(item->node.type, sizeof(char), sizeType, f);
  30.         fread(&item->node.age, sizeof(int), 1, f);
  31.         fread(&sizeId, sizeof(int), 1, f);
  32.         fread(item->node.id, sizeof(char), sizeId, f); 
  33.        
  34.        
  35.        
  36.         if(res_root == NULL)
  37.                 {
  38.                         res_root = item;
  39.                         end_item = res_root;
  40.                 }
  41.                 else
  42.                 {
  43.                         end_item->next = item;
  44.                         end_item = end_item->next;
  45.                 }
  46.        
  47.         }
  48.         fclose(f);
  49. }
  50.  
  51. int animal_typecnt(struct QueueNode* root,char *animalType){
  52.         struct QueueNode* curr_item = root; int num=0;
  53.         while(curr_item != NULL)
  54.         {
  55.                 if(curr_item->node.type==animalType){
  56.                         num++;
  57.                 }
  58.                 curr_item=curr_item->next;
  59.         }
  60.         return num;
  61. }
  62.  
  63.  
  64. int main(int argc, char *argv[]) {
  65.         return 0;
  66. }