Password challenge C Programming

+1 Venkatraman Mathur Narayanaswamy · January 16, 2015
Hi,

I have completed the password challenge and awaiting your feedback for further improvements...

Thanks,

Venkat
--------------------------------------------------------------------------------------------------------------------------------------------------
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include <string.h>
#include <math.h>

/*comments
this is the password program
*/
int main()
{
    int tuna = 'F';
    int a;
    char password[10];
    int pass_length;
    char upperpass = 'N';
    char digitpass = 'N';
    char otherpass = 'N';
    char passchk   = 'N';

    do{
         printf("Enter Password? (Minimum 10 characters)\n");
         scanf("%s",password);
         pass_length = strlen(password);

         printf("password length is: %d \n", pass_length);

         if (pass_length = 10){
               for (a=0;a<=pass_length;a++){
                   printf("%c \n",password[a]);

                   if (isalpha(password[a])){
                       if (isupper(password[a])){
                           upperpass = 'Y';
                        }
                   } else if (isdigit(password[a])){
                       digitpass = 'Y';
                   } else {
                       otherpass = 'Y';
                   }
               }
         }
    }while(pass_length<10 || upperpass=='N' || digitpass=='N' || otherpass=='N');

   return 0;
}

Post a Reply

Replies

Oldest  Newest  Rating
0 Bucky Roberts · January 16, 2015
0 c student · January 16, 2015
you've made an assignment where there probably should have been a comparison:
if (pass_length = 10) ...   // should be ==

which also means that you are only allowing string lengths of ten as acceptable input.

if that was intended then that's fine.
0 Venkatraman Mathur Narayanaswamy · January 16, 2015
ok thanks will review the above comments
  • 1

C

107,087 followers
About

One of the most popular languages of all time.

Links
Moderators
Bucky Roberts Administrator