From 16967bab0d7d80cf595befc01b003d511edd3ac0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Francisco?= Date: Mon, 3 Mar 2025 13:52:30 -0300 Subject: [PATCH] Atempt at making the code more readeble I created the function "generatePassword" wich is an attempt at organizing the code and making it more modular but unfortunately my computer started lagging because of somethings i was doing so im just making this commit to save it but its not done yet. --- .vscode/c_cpp_properties.json | 18 +++++++++++ .vscode/launch.json | 24 ++++++++++++++ .vscode/settings.json | 59 +++++++++++++++++++++++++++++++++++ main.c | 25 ++++++++++----- 4 files changed, 119 insertions(+), 7 deletions(-) create mode 100644 .vscode/c_cpp_properties.json create mode 100644 .vscode/launch.json create mode 100644 .vscode/settings.json diff --git a/.vscode/c_cpp_properties.json b/.vscode/c_cpp_properties.json new file mode 100644 index 0000000..c1b7cd1 --- /dev/null +++ b/.vscode/c_cpp_properties.json @@ -0,0 +1,18 @@ +{ + "configurations": [ + { + "name": "windows-gcc-x64", + "includePath": [ + "${workspaceFolder}/**" + ], + "compilerPath": "C:/Users/joao_/OneDrive/Documentos/devcplusplus/Dev-Cpp/MinGW64/bin/gcc.exe", + "cStandard": "${default}", + "cppStandard": "${default}", + "intelliSenseMode": "windows-gcc-x64", + "compilerArgs": [ + "" + ] + } + ], + "version": 4 +} \ No newline at end of file diff --git a/.vscode/launch.json b/.vscode/launch.json new file mode 100644 index 0000000..06419c4 --- /dev/null +++ b/.vscode/launch.json @@ -0,0 +1,24 @@ +{ + "version": "0.2.0", + "configurations": [ + { + "name": "C/C++ Runner: Debug Session", + "type": "cppdbg", + "request": "launch", + "args": [], + "stopAtEntry": false, + "externalConsole": true, + "cwd": "g:/Meu Drive/00 - 09 - Pessoal/02 - Hobbies/02.02 - C/Simple-Password-Generator", + "program": "g:/Meu Drive/00 - 09 - Pessoal/02 - Hobbies/02.02 - C/Simple-Password-Generator/build/Debug/outDebug", + "MIMode": "gdb", + "miDebuggerPath": "gdb", + "setupCommands": [ + { + "description": "Enable pretty-printing for gdb", + "text": "-enable-pretty-printing", + "ignoreFailures": true + } + ] + } + ] +} \ No newline at end of file diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..3e5eb95 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,59 @@ +{ + "C_Cpp_Runner.cCompilerPath": "gcc", + "C_Cpp_Runner.cppCompilerPath": "g++", + "C_Cpp_Runner.debuggerPath": "gdb", + "C_Cpp_Runner.cStandard": "", + "C_Cpp_Runner.cppStandard": "", + "C_Cpp_Runner.msvcBatchPath": "", + "C_Cpp_Runner.useMsvc": false, + "C_Cpp_Runner.warnings": [ + "-Wall", + "-Wextra", + "-Wpedantic", + "-Wshadow", + "-Wformat=2", + "-Wcast-align", + "-Wconversion", + "-Wsign-conversion", + "-Wnull-dereference" + ], + "C_Cpp_Runner.msvcWarnings": [ + "/W4", + "/permissive-", + "/w14242", + "/w14287", + "/w14296", + "/w14311", + "/w14826", + "/w44062", + "/w44242", + "/w14905", + "/w14906", + "/w14263", + "/w44265", + "/w14928" + ], + "C_Cpp_Runner.enableWarnings": true, + "C_Cpp_Runner.warningsAsError": false, + "C_Cpp_Runner.compilerArgs": [], + "C_Cpp_Runner.linkerArgs": [], + "C_Cpp_Runner.includePaths": [], + "C_Cpp_Runner.includeSearch": [ + "*", + "**/*" + ], + "C_Cpp_Runner.excludeSearch": [ + "**/build", + "**/build/**", + "**/.*", + "**/.*/**", + "**/.vscode", + "**/.vscode/**" + ], + "C_Cpp_Runner.useAddressSanitizer": false, + "C_Cpp_Runner.useUndefinedSanitizer": false, + "C_Cpp_Runner.useLeakSanitizer": false, + "C_Cpp_Runner.showCompilationTime": false, + "C_Cpp_Runner.useLinkTimeOptimization": false, + "C_Cpp_Runner.msvcSecureNoWarnings": false +} \ No newline at end of file diff --git a/main.c b/main.c index 093fddb..51d6337 100644 --- a/main.c +++ b/main.c @@ -2,24 +2,35 @@ #include #include -int main(){ +void generatePassword(int size){ srand(time(NULL)); char caracteres[] = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!@#$%%^&*()"; - int i, size; + char password[128]; + int i, size, maxSize = 128, minSize = 16; + - printf("Digite o tamanho da senha:\n"); + printf("Type the size of the password:\n"); scanf("%d", &size); - if(size <= 0){ - printf("Tamanho Invalido.\n"); - return 1; + + if(size > maxSize){ + printf("Password too big.\nGenerating with %d characteres\n", &maxSize); + size = maxSize; + } else if(size <= 0){ + printf("invalid size.\nGenerating wiht %d characteres\n", &minSize); + size = minSize; } printf("===Senha Gerada===\n"); for(i = 0; i < size; i++){ - printf("%c", caracteres[rand()%72]); + password[i] = caracteres[rand()%72] + printf("%c", password[i]); } printf("\n"); return 0; +} + +int main(){ + } \ No newline at end of file