
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
Cirurgia para acelerar o openSUSE em HD externo via USB
Void Server como Domain Control
Modo Simples de Baixar e Usar o bash-completion
Monitorando o Preço do Bitcoin ou sua Cripto Favorita em Tempo Real com um Widget Flutuante
Como quebrar senha usando john the ripper
[Resolvido] VirtualBox can't enable the AMD-V extension
Como verificar a saúde dos discos no Linux
Como instalar , particionar, formatar e montar um HD adicional no Linux?
Não consigo instalar distro antiga no virtualbox nem direto no hd (22)
Podem me chamar de 1mbecil :) [RESOLVIDO] (29)









