Challenge #1

0 Ahmed Raza · August 2, 2015
Hi, I have posted my code below for challenge #1 for the C Programming course. I've made it to ensure that the user enters a lower case letter, uppercase letter, and the $ sign. Please let me know what you think. :D

#include 
#include
#include
#include
#include

int main () {
char userPass[30];
int goodPass = 0;
printf("Please enter your password: ");
scanf(" %s", userPass);

for(int i=0; i

Post a Reply

Replies

Oldest  Newest  Rating
0 Sha Kal · August 3, 2015
I wanted to post my challenge as well but my code got fucked up the same way as yours here haha, so i deleted.
0 behnam aghakhanian · August 3, 2015
hi bucky
here is my challenge response
it worked, but i'm not sure if it is a good way or not!!
/images/forum/upload/2015-08-03/e0590d78c6c5fa9c028a2b9e2f9fbc38.png
0 Ahmed Raza · August 4, 2015
Aw man, I didn't even notice it got messed up. I posted mine below. Let's see if it looks fine this time.


#include
#include
#include
#include
#include

int main () {
char userPass[30];
int goodPass = 0;
printf("Please enter your password: ");
scanf(" %s", userPass);

for(int i=0; i
0 Sha Kal · August 4, 2015
No it doesnt, take a screenshot of it like i did, save it in your PC and upload it from PC here.
0 Ahmed Raza · August 4, 2015
Okay, here it is.

 /images/forum/upload/2015-08-04/ae7a221eae702b5ccef3362b91a81dfe.png
0 Sha Kal · August 4, 2015
If it works, awesome! :)

Few tips. You could do it all in one loop :D. Other thing is you didn't test it for digit (isdigit), but i'm sure you know how. 

And other thing Bucky didn't show us is, you can limit char input with SCANF. If user puts more than 30 chars here,Buffer Overflow can happen and you could be in some trouble. Way to prevent it is to use: scanf(" %30s", userPass); 

What it will do is it will ignore any other character typed after 30th one as if user didn't type it in.
  • 1

C

106,984 followers
About

One of the most popular languages of all time.

Links
Moderators
Bucky Roberts Administrator