C join
Publicado por Enzo de Brito Ferber (última atualização em 08/01/2013)
[ Hits: 5.906 ]
Homepage: http://www.maximasonorizacao.com.br
Download join.tar (versão 2)
Função que junta um array char** em apenas uma string, todos os elementos separados por um token.
join( {"Enzo", "Ferber"}, ':'); // só demostração!
Retorna: "Enzo:Ferber:"
;)
O arquivo que estou enviando tem o split.c e o join.c
Pra compilar,
$ gcc -c split.c
$ gcc -c join.c
$ gcc -c joinsplit.c
$ gcc -o joinsplit joinsplit.o split.o join.o
$ ./joinsplit Viva o Linux :
:)
Versão 2 - Enviado por Enzo de Brito Ferber em 21/12/2012
Changelog: Script menor e melhor.
Agora trabalha com input do stdin, o que o torna facilmente utilizável com pipes na linha de comando.
$ echo $LS_COLORS | split | join
É exatamente igual a
$ echo $LS_COLORS
Sendo o 'split' o meu script, que também será atualizado.
/* join.c
*
* Enzo Ferber
* dez 2011
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
char *join ( char **elements, char n )
{
register int i;
int length = 0;
char *all;
char **s = elements, *a, *b; // references
/* what length the whole string should have
* +1 for each separator
*/
while ( *s ) length += ( strlen( *(s++) ) + 1 );
/* memory
* +1 for the null terminating char
*/
all = (char *) malloc ( (length + 1) * sizeof(char));
// error check
if ( !all )
{
printf ( "# Error in malloc()\n");
return NULL;
}
// new reference
s = elements;
// whole joined string
b = all;
/*
* @a = each element
*/
while ( (a = *s++) )
{
/*
* copy the element into the joined string
* @a - each character of the element
*/
while ( *a ) *b++ = *a++;
// end of each elements, a separating character
*b++ = n;
}
// null-termination character
*b = 0x0;
// return the string
return all;
}
Função simples de criptografia em um vetor
Nenhum comentário foi encontrado.
IA Turbina o Desktop Linux enquanto distros renovam forças
Como extrair chaves TOTP 2FA a partir de QRCODE (Google Authenticator)
Linux em 2025: Segurança prática para o usuário
Desktop Linux em alta: novos apps, distros e privacidade marcam o sábado
Atualizando o Fedora 42 para 43
Como saber se o seu e-mail já teve a senha vazada?
Como descobrir se a sua senha já foi vazada na internet?
E aí? O Warsaw já está funcionando no Debian 13? [RESOLVIDO] (15)
Secure boot, artigo interessante, nada técnico. (4)
copiar library para diretorio /usr/share/..... su com Falha na a... (1)









