
Enviado em 25/11/2018 - 10:14h
Olá, recetemente andei fazendo uns testes com strings em C e acabei me deparando com um problema esquisito. O problema....estou com preguiça de descrever (- É SERIO ISSO?), então só vou deixar o código abaixo para vocês examinarem e darem o veredito.
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
void get_string(char *__string, size_t max){
fgets(__string, max, stdin);
size_t len=strlen(__string);
if(__string[len-1]=='\n'){
__string[len-1]='\0'; //Tira a quebra de linha (o '\n').
}
}
int main(void){
char secret_word[56];
printf("\n[?] secret_word >");
get_string(secret_word, 56);
size_t wordlen=strlen(secret_word);
char secret[wordlen+1];
printf("\n\n[I] secret_word.........: %s\n", secret_word);
printf("[I] secret_word lenght..: %ld\n\n", wordlen);
for(size_t i=0; i<wordlen; i++){
if(secret_word[i]!=' '){
secret[i]='-';
}else{
secret[i]=' ';
}
}
secret[wordlen+1]='\0';
printf("[I] secret..........: %s\n", secret);
printf("[I] secret lenght...: %ld\n\n", strlen(secret));
return 0;
}
zherkezhi@zherkezhi-Lenovo-B40-30:~/Documents$ ./app
[?] secret_word >abacaxi
[I] secret_word.........: abacaxi
[I] secret_word lenght..: 7
[I] secret..........: -------
[I] secret lenght...: 7
zherkezhi@zherkezhi-Lenovo-B40-30:~/Documents$ ./app
[?] secret_word >macaco
[I] secret_word.........: macaco
[I] secret_word lenght..: 6
[I] secret..........: ------
[I] secret lenght...: 6
zherkezhi@zherkezhi-Lenovo-B40-30:~/Documents$ ./app
[?] secret_word >azeitona
[I] secret_word.........: azeitona
[I] secret_word lenght..: 8
[I] secret..........: --------4
[I] secret lenght...: 9
zherkezhi@zherkezhi-Lenovo-B40-30:~/Documents$ ./app
[?] secret_word >ilha da macacada
[I] secret_word.........: ilha da macacada
[I] secret_word lenght..: 16
[I] secret..........: ---- -- --------�
[I] secret lenght...: 17
Monitorando o Preço do Bitcoin ou sua Cripto Favorita em Tempo Real com um Widget Flutuante
IA Turbina o Desktop Linux enquanto distros renovam forças
Como extrair chaves TOTP 2FA a partir de QRCODE (Google Authenticator)
Ativando e usando "zoom" no ambiente Cinnamon
Vídeo Nostálgico de Instalação do Conectiva Linux 9
Como realizar um ataque de força bruta para desobrir senhas?
Eu queria adicionar a incon do wifi e deixa transparente no fluxbox no... (4)
Thinkpads são bons mesmo ?! (4)
existe algum hub de jogos online similiar ou igual dos browser (6)
Como botar o efeito de deslocar janelas (win + setas - windows) no lin... (0)









