If Else statement problem

This is a discussion on If Else statement problem within the C Programming forums, part of the General Programming Boards category; Hello, brand new to this board and requesting a little help. Have never learned C language but took a number ...

  1. #1
    Registered User
    Join Date
    Nov 2005
    Posts
    5

    If Else statement problem

    Hello, brand new to this board and requesting a little help. Have never learned C language but took a number of C++ courses a few years back [5-6 yrs ago]. Current job has me debugging/enhancing some C code and I can't figure this out.

    Here's the issue: I am trying to put some logging statements in an If Else statement so that I can see which condition is true. When I place logging in the Else portion of the statement, I am getting this error when compiling:

    error C2181: illegal else without matching if

    Here's the code I'm working with:

    Code:
          // If # sign then GbCifSecurity = TRUE and return TRUE
          if ((strcmp(acVastBuf, "CHREND1#") == 0) ||
              (strcmp(acVastBuf, "CHREND2#") == 0) ||
              (strcmp(acVastBuf, "CHREND3#") == 0) ||
              (strcmp(acVastBuf, "CHREND01") == 0) ||
              (strcmp(acVastBuf, "CHREND02") == 0) ||
              (strcmp(acVastBuf, "CHREND03") == 0) ||
    		  (strcmp(acVastBuf, "SUPTPGR#") == 0))
                GbCEPSecurity = TRUE;
     
          // Testing debug statement
          ShLogOpen("H:\\CharitableBlocking.log");
          ShLogWrite("_CINSRCH", "Charitable Blocking - Yes it's in list.");
          ShLogClose();  
    	  
    	  
    	  else
    
    		  
          // Testing debug statement
          ShLogOpen("H:\\CharitableBlocking.log");
          ShLogWrite("_CINSRCH", "Charitable Blocking - No it's not in list.");
          ShLogClose();  
    
    	  
                GbCEPSecurity = FALSE;
       }

  2. #2
    ZuK
    ZuK is offline
    Registered User
    Join Date
    Aug 2005
    Location
    Austria
    Posts
    1,990
    You need to put some { } around your debug statements

    Code:
        // If # sign then GbCifSecurity = TRUE and return TRUE
          if ((strcmp(acVastBuf, "CHREND1#") == 0) ||
              (strcmp(acVastBuf, "CHREND2#") == 0) ||
              (strcmp(acVastBuf, "CHREND3#") == 0) ||
              (strcmp(acVastBuf, "CHREND01") == 0) ||
              (strcmp(acVastBuf, "CHREND02") == 0) ||
              (strcmp(acVastBuf, "CHREND03") == 0) ||
    		  (strcmp(acVastBuf, "SUPTPGR#") == 0)) {
                GbCEPSecurity = TRUE;
     
          // Testing debug statement
          ShLogOpen("H:\\CharitableBlocking.log");
          ShLogWrite("_CINSRCH", "Charitable Blocking - Yes it's in list.");
          ShLogClose();  
    	  
    	  }
    	  else {
    
    		  
          // Testing debug statement
          ShLogOpen("H:\\CharitableBlocking.log");
          ShLogWrite("_CINSRCH", "Charitable Blocking - No it's not in list.");
          ShLogClose();  
    
    	  
                GbCEPSecurity = FALSE;
          }
       }
    Kurt

  3. #3
    Registered User
    Join Date
    Nov 2005
    Posts
    5
    Ahhhh, syntax, syntax, syntax. Shoulda figured it was something like that.

    Thanks very much for your quick response; worked perfectly.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Switch statement problem
    By jalex39 in forum C Programming
    Replies: 6
    Last Post: 03-08-2008, 04:05 PM
  2. having problem with string statement during a loop!
    By Hp7130p in forum C++ Programming
    Replies: 5
    Last Post: 04-21-2005, 10:40 AM
  3. If statement re-do problem
    By RoD in forum Windows Programming
    Replies: 5
    Last Post: 09-11-2002, 05:46 PM
  4. Major Problem
    By Unregistered in forum C++ Programming
    Replies: 3
    Last Post: 02-19-2002, 01:06 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21