I think that the main problem on my code is that iam trying to pass a struct through another struct .

Is there a problem if i use "->" instead of (*). ?

Because it keeps showing me an error that say's : invalid type of argument '->'

Iam trying about 8 hours and iam really exhausted. I think the mistake is obvious but for the moment my mind is off... :-/

//Include
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include <string.h>
//Include-----------------

//Records
typedef enum
{
    FALSE,TRUE
}boolean;

typedef struct
{
    char name[25];    
}app;





typedef struct
{
    int Front;
    int Rear;
    app applist[2];

}clinic;


typedef struct
{
    int Front;
    int Rear;
 char name[25];
  int choice;
  char phone[10];  

}wait;
//Records ------------------------------------------


//functions
void NewAppointment(int y,clinic *clinic,wait *wait);
int RandomInteger(void);
void CreateQ(clinic *clinic,int i);
void CreateQw(wait *wait);
boolean EmptyQ(clinic clinic,int y);
boolean EmptyQw(wait wait);
boolean FullQ(clinic clinic,int y);
boolean FullQw(wait wait);
void AddQ(clinic *clinic, int y,wait *wait);
void ShowWaitingQ(wait *wait);
void ShowQ(clinic *clinic);

//functions ----------------------------------------------------


//=====================================MAIN===============================
main()
{
    char ep;
    clinic clinic[6];
    wait wait[20];
    int i,y;
    // Äçìéïõñãßá ôùí 6 ïõñþí ! (5 ïõñÝò ãéá ñáíôåâïý êáé ìßá waiting list)
    for(i=1;i<6;i++)
    CreateQ(&clinic,i);

    CreateQw(&wait);

    //ÔÝëïò ôçò Äçìéïõñãßáò ôùí 6 ïõñþí!

    //ÅðáíáëçðôéêÞ äéáäéêáóßá ðïõ êáëåß ôéò óõíáñôÞóåéò
   while(TRUE)
   {
        y=RandomInteger();
        NewAppointment(y,&clinic,&wait);
        printf("Continue? Y/N ( Y=Yes , N=No )\n");
        scanf("%c",ep);
        if((ep=='n')||(ep=='N'))break;     
   }
   //ÅðáíáëçðôéêÞ äéáäéêáóßá ðïõ êáëåß ôéò óõíáñôÞóåéò------------------------- 

   //Ôåëåõôáßåò Åìöáíßóåéò <><><><><><><><><><><<><>>
   ShowQ(&clinic);
   ShowWaitingQ(&wait);





 system("pause");   
}
//=================================MAIN=====================================


//ShowWaitingQ
void ShowWaitingQ(wait *wait)
{
    int Front;
   printf("Waiting List:\n");
   while(wait->Front!=wait->Rear)
   {
        printf("%s , %d , %s",wait[Front]->name,wait[Front]->choice,wait[Front]->phone);
        printf("\n");
        wait->Front = wait->Front +1;
   }  


}
//ShowWaitingQ-----------------------------------------------
void ShowQ(clinic *clinic)
{
    int i;

    for(i=1;i<6;i++)
    {
        printf("Appointments of clinic %d : \n",i);
      while(clinic[i]->Front!=clinic[i]->Rear)
      {
            printf("%s",clinic[i]->applist[clinic[i]->Front]->name);
            printf("\n");
            clinic[i]->Front=clinic[i]->Front +1;      
      }  


    }
}



//NewAppointment 
NewAppointment(int y,clinic *clinic,wait *wait)
{
    AddQ(&clinic,y,&wait);
}
//NewAppointment -------------------------------

//Random
int RandomInteger(void)
{
    int n;
    n=rand()%5;
    n++;
return(n);
}
//Random----------------------------------


// Ïé Äéáäéêáóßåò Create
void CreateQ(clinic *clinic,int i)
{
    clinic[i]->Front = 0;
    clinic[i]->Rear = 0;


}

void CreateQw(wait *wait)
{
    wait->Front=0;
    wait->Rear=0;
}
// Ïé Äéáäéêáóßåò Create--------------------------

//Ïé Äéáäéêáóßåò   Empty
boolean EmptyQ(clinic clinic,int y)
{
    return (clinic[y].Front == clinic[y].Rear);
}

boolean EmptyQw(wait wait)
{
    return(wait.Front == wait.Rear);
}
//Ïé Äéáäéêáóßåò   Empty------------------------------

//Ïé Äéáäéêáóßåò   Full
boolean FullQ(clinic clinic,int y)
{
    return ((clinic[y].Front) == ((clinic[y].Rear +1) % 2));
}

boolean FullQw(wait wait)
{
    return((wait.Front) == ((wait.Rear +1) % 20));
}

//Ïé Äéáäéêáóßåò   Full--------------------------------


// Äéáäéêáóßá Add
void AddQ(clinic *clinic, int y,wait *wait)
{
    int NewRear;
    int NewRear1;
    int Rear;
    char onoma[25];
    char number[10];
    printf("\n Give your name: ");
    if(!FullQ(clinic,y))
    {
        scanf("%s",onoma);
        printf("\nSuccesful appointment for clinic %d ",y);
        strcpy(clinic[y]->applist[clinic[y]->Rear]->name,onoma);
        NewRear = (clinic[y]->Rear + 1) % 2; 
        clinic[y]->Rear = NewRear;
    }
    else if(!FullQw(wait))
    {
        scanf("%s",onoma);
        printf("You are in a Waiting list : ");
        strcpy(wait[Rear]->name,onoma);
        wait[Rear]->choice=y;
        printf("\n Give Your Phone Numer : ");
        scanf("%s",number);
        strcpy(wait[Rear]->phone,number);
        NewRear1=(wait->Rear +1) % 20;
        wait->Rear=NewRear1;
    }
        else
         printf("Waiting List is FULL ");
}

// Äéáäéêáóßá Add---------------------------------------------------------------

Unlike C++, C language requires the data type on line 27, the symbol app by itself is not a data type. It should be struct app applist[2];

wait[] is an array of structures, not an array of pointers to structures. So you need to use the . operator instead of -> operator, something like this:

printf("%s , %d , %s",wait[Front].name,wait[Front].choice,wait[Front].phone)

commented: any ideas for the errors ? Thanks for struct and the operaton thing. +0

So there is no problem with my clinic-> ???

Can you compile it to see the errors or do you want me to take a snapshot ?

These are the errors i keep getting when im trying to compile

lines 69, 71, 79, 87 and 88: remove & from the parameters -- they are already arrays. When passing an array all you do is enter the name of the array, adding & operator makes it a pointer to the array (like wait**), which is not what you want.

line 81: scanf() needs a pointer to the variable where it is to store the data. So on this line you need the & to make ep a pointer, since all it is is a char.

line 104: wait->Front makes no sense because want is an array. Which element of wait do you mean? wait->Front is the same as wait[0].Front

line 107: I've already shown you how to fix that and other similar lines.

line 108: Same comment as for line 104 above.

commented: thanks +0

I keep getting those errors.

My question is the above:

Do structs need a pointer for passing through functions ? When i need to pass a struct as a pointer ? When its not an array maybe ?

Look at the attachments

Thanks for your help Ancient Dragon

I thought I already answered your question. If you are passing an array of structures you don't need the & operator, just the name of the array because arrays are always passed as pointers. If you are passing a single structure then you need the & operator to make a pointer.

Thanks i will check it tommorow and if nothing works i will ask again :-P

Sorry for the confusion

Be sure to post new code. I'm not showing you all the errors in your program. You should be able to find the rest by using the examples that I did show you. Compile the program, look at the first error message, fix it, then compile again. Fixing one error will likely resolve several error messages.

I've made the code with a second way instead of the 1st one:

Now it works but it's totally diferrent i think.

#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include <time.h>
#include <string.h>

#define QueueLimit1 3
#define QueueLimit2 21





typedef enum{
    FALSE,TRUE
}boolean;

typedef char QueueElementType1[25];

typedef struct{
    char name[25];
    int code;
    char phone[10];
}QueueElementType2;


typedef struct{
    int Front,Rear;
    QueueElementType1 Element[QueueLimit1];
}QueueType1;

typedef struct{
    int Front,Rear;
    QueueElementType2 Element[QueueLimit2];
}QueueType2;


void CreateQ(QueueType1 *Queue);
void CreateQ2(QueueType2 *Queue);
boolean EmptyQ(QueueType1 Queue);
boolean EmptyQ2(QueueType2 Queue);
boolean FullQ(QueueType1 Queue);
boolean FullQ2(QueueType2 Queue);
void AddQ(QueueType1 *Queue, QueueElementType1 Item);
void AddQ2(QueueType2 *Queue, QueueElementType2 Item);
void ShowQ(QueueType1 Queue);
void ShowWaitingQ(QueueType2 Queue);
int  RandomInteger();

void NewAppointment(int code, QueueType1 *Queue, QueueType2 *WQ);

void NewAppointment(int code, QueueType1 *Queue, QueueType2 *WQ)
{
    QueueElementType1 name;
    QueueElementType2 wait;
    if(!FullQ(*Queue))
    {
        printf("Give your name: ");
        fflush(stdin);
        scanf("%s",name);
        AddQ(&(*Queue),name);
        printf("Successful appointment for clinic %d\n",code);
    }
    else
    {
        printf("Give your name: ");
        fflush(stdin);
        scanf("%s",wait.name);
        printf("\nYou are in a waiting list\n");
        printf("Give your phone number:  ");
        fflush(stdin);
        scanf("%s",wait.phone);
        wait.code=code;
        AddQ2(&(*WQ),wait);   
    }



}

main()
{
    char ans;
    int ch,i;
    QueueType1 Q[6];
    QueueType2 WQ;

    for(i=1;i<=5;i++)
    CreateQ(&Q[i]);

   CreateQ2(&WQ);

    do
    {
         srand(time(NULL));
        ch=RandomInteger();

        NewAppointment(ch,&Q[ch],&WQ);


        printf("Do you want to continue ?  Y/N ?--> :  ");
        fflush(stdin);
        scanf("%c",&ans);

    }while (ans=='y'||ans=='Y');

    printf("\n");

    for(i=1;i<=5;i++)
    {
       printf("Appointments of clinic %d:\n",i);
       ShowQ(Q[i]);
    }


    printf("Waiting list:\n");
    ShowWaitingQ(WQ);
    printf("\n");
    printf("\n FINALLY THE END \n");




system("pause");    
} 
int  RandomInteger()
{
  int n;
  n=rand() % 5 +1;  
  return(n);  
}

void CreateQ(QueueType1 *Queue)

{
    //(*Queue.Front)=0;
    Queue->Front = 0;
    Queue->Rear = 0;
}

void CreateQ2(QueueType2 *Queue)

{
    Queue->Front = 0;
    Queue->Rear = 0;
}



boolean EmptyQ(QueueType1 Queue)

{
    return (Queue.Front == Queue.Rear);
}

boolean EmptyQ2(QueueType2 Queue)

{
    return (Queue.Front == Queue.Rear);
}


boolean FullQ(QueueType1 Queue)

{
    return ((Queue.Front) == ((Queue.Rear +1) % QueueLimit1));
}


boolean FullQ2(QueueType2 Queue)

{
    return ((Queue.Front) == ((Queue.Rear +1) % QueueLimit2));
}



void AddQ(QueueType1 *Queue, QueueElementType1 Item)

{
    int NewRear;

    if(!FullQ(*Queue))
    {
        NewRear = (Queue ->Rear + 1) % QueueLimit1;
        strcpy(Queue ->Element[Queue ->Rear],Item);
        Queue ->Rear = NewRear;
    }
    else
        printf("Full Queue");
}

void AddQ2(QueueType2 *Queue, QueueElementType2 Item)

{
    int NewRear;

    if(!FullQ2(*Queue))
    {
        NewRear = (Queue ->Rear + 1) % QueueLimit2;
        Queue ->Element[Queue ->Rear] = Item;
        Queue ->Rear = NewRear;
    }
    else
        printf("Full Queue");
}


void ShowQ(QueueType1 Queue) {
    int current;
    current = Queue.Front;
    while (current != Queue.Rear) {
        printf("%-10s \n", Queue.Element[current]);
        current = (current + 1) % QueueLimit1;
    }
    printf("\n");
}

void ShowWaitingQ(QueueType2 Queue) {
    int current;
    current = Queue.Front;
    while (current != Queue.Rear) {
        printf("%-10s, %d, %s \n", Queue.Element[current].name,Queue.Element[current].code,Queue.Element[current].phone);
        current = (current + 1) % QueueLimit2;
    }
    printf("\n");
    printf("\n");
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.