Results 1 to 4 of 4
  1. #1
    "Expected expression before 'else'" problem

    Member Since
    May 16, 2010
    Posts
    2
    Unhappy "Expected expression before 'else'" problem
    Hello everyone,
    I am a newb to programming and have done a few hours of C,
    I was writing this program for use as a start up program in Terminal but i got the error message Expected expression before else, when compiling in Xcode,
    i had an "if" statement before and there are curly braces at the end of the "if" statement,


    Code:
    #include <stdio.h>
    
    void Hello( void );
    void Failed( void );
    
    int main (int argc, const char * argv[]) {
    	char pass1, pass2, pass3;
    	
    	Hello();
    	
    	scanf("%c,%c,%c", &pass1, &pass2, &pass3);
    	
    	getchar();
    	
    	if (&pass1 == "p", &pass2 == "w", &pass3 == "d"); 
    	{
    		printf("Continue!\n");
    	} 
    	else {
    		Failed();
    	}
    }
    	
    void Hello( void ) {
    	printf("Welcome to Unix!\n");
    	getchar();
    	printf("Password?\n");
    }
    
    void Failed( void ) {
    	int inf1;
    	inf1 = 1;
    	printf("Leave now.");
    	while (inf1 > 2) {
    		printf("Leave now.");
    	}
    }
    any help would be greatly appreciated, thanks!

  2. #2
    &quot;Expected expression before 'else'&quot; problem
    McBie's Avatar
    Member Since
    Apr 26, 2008
    Location
    Belgium
    Posts
    2,673
    Specs:
    2013 MBA 13" - OS X 10.10.5
    Why is there a semicolon after the first " if " statement ?

    Cheers ... McBie
    A computer lets you make more mistakes faster than any invention in human history - with the possible exceptions of handguns and tequila.
    The bitterness of poor quality remains long after the sweetness of low price is forgotten.

  3. #3
    &quot;Expected expression before 'else'&quot; problem
    scathe's Avatar
    Member Since
    Jan 12, 2009
    Location
    Prague, Czech Republic
    Posts
    1,096
    Specs:
    2,4Ghz 15" unibody
    you've got a semicolon between the if statement and the following code block.

    use:
    if(){
    }
    not:
    if();{
    }

    Edit:
    McBie beat me to it, Cheers

  4. #4
    &quot;Expected expression before 'else'&quot; problem

    Member Since
    May 16, 2010
    Posts
    2
    ahhh thanks alot guys

    school boy error =P

    greatly appreciated guys thanks again

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Replies: 1
    Last Post: 02-16-2015, 02:40 AM
  2. Pages "Capitalization" doesn't work as expected
    By davidjoho in forum OS X - Apps and Games
    Replies: 0
    Last Post: 12-24-2010, 11:48 AM
  3. Expected Memory for the New "Apps"?
    By MacDad77 in forum iPhone Hardware and Accessories
    Replies: 3
    Last Post: 05-20-2008, 06:25 PM
  4. Replies: 0
    Last Post: 03-28-2008, 08:19 PM
  5. Replies: 1
    Last Post: 02-26-2008, 10:26 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •