Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create randompassword.c #190

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions randompassword.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#include <stdio.h>
#include <stdlib.h>
#include <time.h>

char generateRandomChar() {
int randChoice = rand() % 4;

if (randChoice == 0)
return 'A' + (rand() % 26); // Uppercase letter
else if (randChoice == 1)
return 'a' + (rand() % 26); // Lowercase letter
else if (randChoice == 2)
return '0' + (rand() % 10); // Digit
else
return "!@#$%^&*()_+-=[]{}|;:,.<>?"[rand() % 20]; // Special character
}

void generatePassword(int size) {
for (int i = 0; i < size; i++) {
printf("%c", generateRandomChar());
}
printf("\n");
}

int main() {
int size;
printf("Enter the length of the password: ");
scanf("%d", &size);

srand(time(NULL)); // Seed the random number generator

printf("Generated password: ");
generatePassword(size);

return 0;
}