This password program for visual studio\'s 2010 works great. Just need it writte
ID: 3623418 • Letter: T
Question
This password program for visual studio's 2010 works great. Just need it written so that every function is in it's own function header. For instance, the 8 characters only requirement should have it's own function and the requirment that there must be at least one letter and one number in the password should be another function and so on. So there should be four functions with four function prototypes. The functions should be passed or called in main. The idea is that the program is suppose to be structured so that each function has it's own header and block instead of it all being inside main. Thanksprintf("Enter a password: ");
scanf("%s",&pw);
for(i=0;i<pw[i]!='';i++)
if(isdigit(pw[i]) )
digit++;
else if(isalpha(pw[i]))
alpha++;
if(i!=8)
{printf("must have exactly 8 characters ");
good=1;
}
if(digit==0)
{printf("must have at least 1 digit ");
good=1;
}
if(alpha==0)
{printf("must have at least 1 alphabetic character ");
good=1;
}
if(digit+alpha!=8)
{printf("must have only alphabetic characters and digits ");
good=1;
}
printf(" ");
}while(good!=0);
printf("%s is a valid password ",pw);
_getch();
return 0;
}
Explanation / Answer
please rate - thanks
#include <stdio.h>
#include<conio.h>
int checkchars(int);
int checkdigit(int);
int checkalpha(int);
int checkall(int,int);
int main()
{char pw[15];
int a,b,c,d,digit,alpha,i;
do
{digit=0;
alpha=0;
printf("Enter a password: ");
scanf("%s",&pw);
for(i=0;i<pw[i]!='';i++)
if(isdigit(pw[i]) )
digit++;
else if(isalpha(pw[i]))
alpha++;
a=checkchars(i);
b=checkdigit(digit);
c=checkalpha(alpha);
d=checkall(alpha,digit);
printf(" ");
}while(a+b+c+d!=0);
printf("%s is a valid password ",pw);
getch();
return 0;
}
int checkchars(int i)
{if(i!=8)
{printf("must have exactly 8 characters ");
return 1;
}
return 0;
}
int checkdigit(int digit)
{if(digit==0)
{printf("must have at least 1 digit ");
return 1;
}
return 0;
}
int checkalpha(int alpha)
{if(alpha==0)
{printf("must have at least 1 alphabetic character ");
return 1;
}
return 0;
}
int checkall(int digit,int alpha)
{if(digit+alpha!=8)
{printf("must have only alphabetic characters and digits ");
return 1;
}
return 0;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.