Thread: Errors in code. Why?

  1. #1
    Registered User
    Join Date
    Nov 2016
    Posts
    3

    Errors in code. Why?

    Code:
    #include <stdio.h>#include <string.h>
    #include <ctype.h>
    
    
    int main() 
    { 
    char password[20]; 
    int length_check(char[]);
    int no_symbols(char[]);
    int at_least_two_digit(char[]); 
    int a,b,c,r;  
    do 
    { 
    printf("Enter your test password: "); 
    scanf("%s",password);
     
     a = length_check(password); 
     b = no_symbols(password); 
     c = at_least_two_digit(password); 
     r=a+b+c;
     if(a==0) 
         printf("Must have more than eight characters.\n"); 
     if(b==0) 
         printf("Must consist of only alphabetic characters and digits\n"); 
     if(c==0) 
         printf("Must consist of at least two numbers 0-9.\n");
     } 
     while(r!=3); 
     printf("Invalid password!\n");
        
    else 
        printf("Valid Password!\n");
     
     return 0; 
     
     }
     
     int length_check(char p[])
     {
         int pass;
         
         pass = strlen(p);
         
         if(pass<8);
            return 1;
         else
            return 0;
     }
     
     int no_symbols(char p[])
     {
         int i=0;
         int w=0;
         
         while (p[i] != '\0')
         {
             if(ispunct(p[i]) !=0)
                w++;
                i++;
         }
         if (w==0)
             return 1;
         else 
             return 0;
     }
     
     int at_least_one_digit(char p[])
     {
         int i=0;
         int w=0;
         
         while (p[i] != '\0')
         {
             if(isdigit(p[i])!=0)
                 w++;
             i++;
        
         }
         if(w>=2)
             return 1;
         else 
             return 0;
     }
    Compiling on a mac.

    31:1: error: expected expression
    else
    ^
    password.c:44:13: warning: if statement has empty body [-Wempty-body]
    if(pass<8);
    ^
    password.c:44:13: note: put the semicolon on a separate line to silence this
    warning
    password.c:46:3: error: expected expression
    else

    Any help is appreciated.

  2. #2
    Its hard... But im here swgh's Avatar
    Join Date
    Apr 2005
    Location
    England
    Posts
    1,688
    else
    printf("Valid Password!\n");
    "else" statements require their native "if" to be in the same scope of the code - not outside it.

    The other errors are pretty self explained by the compiler. Hint: Placing a semicolon after a control statement that
    does not require it can result in the entire statement being ignored or wrongly executed.
    Double Helix STL

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. What is the errors in this code? please help
    By Ma'd Saeed in forum C++ Programming
    Replies: 3
    Last Post: 05-08-2014, 06:29 AM
  2. Getting errors in my code
    By Hasnat Abul in forum C Programming
    Replies: 7
    Last Post: 11-02-2012, 03:26 AM
  3. Help with errors on my code!
    By ashleyd in forum C++ Programming
    Replies: 7
    Last Post: 10-30-2011, 01:35 PM
  4. Replies: 2
    Last Post: 05-09-2010, 11:30 PM
  5. Errors in code
    By itzme in forum C++ Programming
    Replies: 12
    Last Post: 01-07-2005, 05:11 PM

Tags for this Thread