Jump to content
kruder

inicializar vector com cararacteres de outro vector aleatoriamente

Recommended Posts

kruder

Boas pessoal! Gostaria de saber como posso inicializar um vector 4x5 com os caracteres de outro vector aleatoriamente?

Agradeço ajuda!

Obrigado

Share this post


Link to post
Share on other sites
Cr4zYPT

tipo podes inicializar um 4x5 normalmente

int vetor=[4][5];

e agora metes o que quiseres no vetor

Share this post


Link to post
Share on other sites
HappyHippyHippo

esqueceste dizer qual o "formato" do outro vector.

mas o mais fácil é fazer um cast para um vector unidimensional e fazer um ciclo de 0 a (4x5) com um rand a ir buscar os elementos do vector origem


IRC : sim, é algo que ainda existe >> #p@p

Share this post


Link to post
Share on other sites
kruder

Tipo isto?? nao percebi a cena do cast

void iniciar(char s[DIM1][DIM2])
{
    int i, j;
    char car[ ]={'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t'};
   
    for (i=0;i<DIM1;i++)
    {

        for (j=0;j<DIM2;j++)
        {           
                s[ i ][ j ]=rand(car);
        }
    }
}

Obrigado pela ajuda

Share this post


Link to post
Share on other sites
HappyHippyHippo

nop ... (tirando os erros de linguagem) tipo:

char dest[4][5];
char src[sRC_SIZE];
char * aux;
...
// iniciar o array src
...
aux = (char *)dest;
for (iter = 0; iter < 4*5; iter++) {
  aux[iter] = src[rand % SRC_SIZE];
}
...


IRC : sim, é algo que ainda existe >> #p@p

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...

Important Information

By using this site you accept our Terms of Use and Privacy Policy. We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.