I have my program mostly figured out, but the teacher wants us to "add a,b,c & d (into r) and check for r!=4". How do would I do this?
Also, why do my last statements only work if i return 1 for if it does not work?
Thanks.
Code:
#include <stdio.h>
#pragma warning(disable:4996)
#include <string.h>
#include <ctype.h>
void explanation();
/* Set up the check functions to return a 1 if the password passes */
/* and a zero if not! */
int length_check(char[]);
int no_symbols(char[]);
int at_least_one_digit(char[]);
int at_least_one_letter(char[]);
int main()
{
char password[20];
int a, b, c, d, r;
do
{
printf("Enter your test password\n");
scanf("%s",password);
a = length_check(password);
{
if(a==0)
printf("Must consist of atleast 8 characters or digits\n");
}
b = no_symbols(password);
{
if(b==0)
printf("Must consist of only alphabetic characters and digits\n");
}
c = at_least_one_digit(password);
{
if(c==1)
printf("Must consist of atleast one digits\n");
}
d = at_least_one_letter(password);
{
if(d==1)
printf("Must consist of atleast one alphabetic character\n");
}
}while(r!=1); /*Hint: add a,b,c & d (into r) and check for r!=4 */
printf("Legal password!\n");
scanf("%s",password);
return 0;
}
int length_check(char p[])
{ int i=0,w=0;
while(p[i] != '\0')
{
if((int)strlen(p)!=0)
w++;
i++;
}
if(w>=7)
return 1;
else
return 0;
}
int no_symbols(char p[])
{ int i=0,w=0;
while(p[i] != '\0') /* Strings are terminated with the null character */
{
if(ispunct(p[i])!=0)/*I suggest a google search for ispunct */
w++;
i++; /* Move through the string */
}
if(w==0)
return 1;
else
return 0;
}
int at_least_one_digit(char p[])
{ int i=0,w=0;
while(p[i] != '\0')
{
if(isdigit(p[i]))
w++;
i++;
}
if(w==0)
return 1;
else
return 0;
}
int at_least_one_letter(char p[])
{ int i=0,w=0;
while(p[i] != '\0')
{
if(isalpha(p[i])!=0)
w++;
i++;
}
if(w==0)
return 1;
else
return 0;
}