We help IT Professionals succeed at work.
Get Started
Troubleshooting Question

My C/C++ if statement is not working as planned

LeighWardle asked
Last Modified: 2020-11-10
Hi Experts,

Here's my code:

int myRecon(char *server,int retrycount, int retries)
    int retriesremaining;
   int minutesremaining;
   char buffer[1024];
   retriesremaining = retries - retrycount;
   minutesremaining = 2*retriesremaining;

//   skip message if retries > retrycount
   if (retries > retrycount)
   sprintf(buffer, "Lost connection with the Licence Server.\nIt's most likely your Internet connection is broken.\nAttempting to reconnect every 2 minutes.\nIf the connection is not working in %d minutes, CIRCLY will automatically close, so the Licence can be returned to the Licence Server.\n\nretrycount=%d, retries=%d", minutesremaining,retrycount,retries);
        "Connection Status",

My problem is that when retries = 2 and retrycount = 2, the  if (retries > retrycount) statement executes as True, but it should be False.


Watch Question
This problem has been solved!
Unlock 1 Answer and 14 Comments.
See Answer
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant

An Experts Exchange subscription includes unlimited access to online courses.

Get Started
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE