i need help making a password program. it lets the use input a password and check it if it is following the password rules, which are the following:

must have exactly 7 characters, only alphabets and digits are allowed.

i don't exactly know how to put that in an if else function, but i know i have to use that.

i also don't know if the string.h library is needed but, in our book, the question was from a chapter with strings.

use "strlen" and check character ranges. look at your ascii table.

post some code if you want any more advice.

i guess i can use that to check the length, and use the if else to see if the length is exactly 7.
and since the password is supposed to be 7 would i need to make the array size 8 for the \0 part of the string?

since u told me to post a code im gonna try but i know its wrong.

#include <stdio.h>
#include <string.h>

int main (void)
	int length;
	char pass[8];
	printf("Enter a password with 8 characters.");
	printf("It must have at least 1 digit and 1 alphabet.");

	fgets( pass, 8, stdin);

that's what i have for now, im trying to add the if function with strlen in it

Use the length() function and return a boolean

string str ("pasword");

if str.length() < 7 {
return 0;
return 1:

commented: sorry. this is wrong on two counts. you've been around long enough to know better -2

that doesnt help him if his password is supposed to be EXACTLY seven characters, now does it?

and this is C, not C++

After reading in the password call functions to test each individual rule. Don't try to test all things in one function, or ghod forbid right after the read.


int main()
char un[7],pwd[10];
int i,f;
printf("\nEnter user name and pwd");
printf("pwd error");

I think the question is incomplete and need more details...........