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
Como gerar qualquer emoji ou símbolo unicode a partir do seu teclado
Instalar e Configurar o Slackware Linux em 2025
Como configurar os repositórios do apt no Debian 12 em 2025
Passkeys: A Evolução da Autenticação Digital
Instalação de distro Linux em computadores, netbooks, etc, em rede com o Clonezilla
Muitas dificuldades ao instalar distro Linux em Notebook Sony Vaio PCG-6131L (VPCEA24FM)
Slackpkg+ (Slackpkg Plus) está de volta!
Como dividir duas janelas igualmente e lado-a-lado na sua tela
Configurando o Conky para iniciar corretamente no sistema
3 configurações básicas que podem melhorar muito a sua edição pelo editor nano
Problemas com SQL em objeto TLabel ... (1)
Youtube e networkmeneger para de funcionar (5)
Minha rede tem um espaço invisível que não dá pra digitar o nome da re... (1)
Pedagogia no brasil não passa de alfabetização por m4sturbação mental ... (2)