-1

I'm building a system of 2 servers and 1 client for reservations. I found an obstacle, now I'll explain:
-server A
-server B
-client

Once the client selects from a menu what he wants to book and when, server B must look in the struct for the date and check if it is available, if it is send an ok, if it is not send a no as an answer.
To do it I had thought of the following way, but it does not work:

bool search(int bet2,  bool flag)
    {
     int i=0;

      for(i=0; i < 11; i++){
        if(strcmp(content[i].date, content[bet2].date) == 0)
        {
           if (content[i].mark == true)
           {
               printf("Date Busy");
               return false;
           } else {
               content[i].mark = true;  
               printf("Date booked day: %s",content[i].date);   
               return true;
            }}
      }
    }

in the prototypes I declare it so:

bool search (int bet2, bool flag);

in the main I declare it so:

search (bet2, flag);

the struct is this:

typedef struct choice {
    char name [40];
    char date [40];
    bool mark;
} Choice;

Choice content [10];

now I have a doubt, but the type bool exists in C?

anyway, where am I wrong?

sorry but I'm writing lines of code this morning and I'm stuck here, probably I do not see it.

this code return ever that date is good, where am i wrong?

Rock
  • 33
  • 8
  • That is not the code you compiled, not even a part of it. At least the `Else` would make an compiler complain. Please turn this into a MCVE. – Yunnosch Jan 15 '18 at 16:39
  • sorry guys, but as I did the copy and paste it has pasted so, it's not my fault and I did not notice, I posted directly, after the post is edited by yunnosch – Rock Jan 15 '18 at 17:19
  • Please note, people here can tell that the error was not done by me. Maybe you want to rephrase that comment. – Yunnosch Jan 15 '18 at 17:23
  • 1
    @Rock.: Yunnosch did a good job editing the question and before that I edited it - nobody added that extra `}` apart from you. Don't blame like this. – user2736738 Jan 15 '18 at 17:25
  • @Rock.: Again you make your code unformatted. – user2736738 Jan 15 '18 at 17:26
  • Apart from insisting on improvable code formatting, you also gave a problem description "it does not work". Please elaborate on that, maybe giving some details of behaviour in contrast to desired behaviour. – Yunnosch Jan 15 '18 at 17:34
  • 1
    @Rock.: You edited the question - and now you have modified your question looking at my answer.. Dont edit the question like this after answered! – user2736738 Jan 15 '18 at 17:34
  • 1
    This has now become a "moving target question". This is quite a reliable way of discouraging potential answerers. I feel with you @coderredoc. – Yunnosch Jan 15 '18 at 17:36
  • you asked me for the correct code I ran and I glued it and I apologized for the first time because I did copy and paste and the text was glued incorrectly. – Rock Jan 15 '18 at 17:39
  • Congratulations, the last edit has introduced a conflict between parameter and local variable, both called "flag", but of different type. – Yunnosch Jan 15 '18 at 17:39
  • give me time to fix things, otherwise it is useless for you to write it down – Rock Jan 15 '18 at 17:40
  • Please, pleae. Create a correct [mcve], including a good error decription. Doing that right away would have avoided the (from your point of view) unhelpful answer and would have avoided the conflicts you create by editing manually. – Yunnosch Jan 15 '18 at 17:41
  • it is useless to do the pundits, if you want to help do not be vain, otherwise avoid commenting – Rock Jan 15 '18 at 17:41
  • For the purpose of having time to edit your question in peace, delete it, edit it, double-check it, then undelete it when you are really done. – Yunnosch Jan 15 '18 at 17:42
  • ok i clean, but the code not work correctly – Rock Jan 15 '18 at 18:21
  • this function not return the bool – Rock Jan 15 '18 at 18:47
  • there's no "return" statement at the end of the method. if the loop ends without calling the inner return statements, behaviour is undefined. – Jean-François Fabre Jan 15 '18 at 20:39

1 Answers1

0
content [i] .mark = true

will be

content [i] .mark == true

To avoid this kind of problem you can use the comparison like this

true == content [i] .mark

In this case even if you forget the == and use = the compiler will complain.

And yes even better is to use simple and easy to read

  if( content [i] .mark )

Also there is no keyword called Else in C. It will be else.

Remove the extra } in the code where you have written }}. The scoping changes for that and it is wrong.

Also why use return flag = false it's useless here. Just do return false or return true. Because flag's changed value won't be used anywhere.

user2736738
  • 30,591
  • 5
  • 42
  • 56