Ir para conteúdo
Fórum Script Brasil

WesleyMS

Membros
  • Total de itens

    3
  • Registro em

  • Última visita

Posts postados por WesleyMS

  1. Ah sim, pude rodar o codigo agora, foi muito util, alterei a rand  para 7 e não deu mais falhas

    #include <stdio.h>
    #include <time.h>
    #include <stdlib.h>
    #include <string.h>
    
    int main ()
    {
        char nomepronto[2][50];
        
        char nome1[8][50] = {"DRAGAO","LADRAO","REI","POLVO","MONSTRO","LEAO","HOMEM"};
        
        char nome2[8][50] = {" ESMAGADOR DE"," COMEDOR DE"," VENDEDOR DE"," CHUPADOR DE", " ARRANCADOR DE", " MANIPULADOR DE"," FURTADOR DE"," ADORADOR DE"};
        
        char nome3[8][50] = {" CABEÇAS", " TRIPAS", " OSSOS", " SANGUE", " OLHOS", " CACHORRO", " COBRAS", " DEMONIOS"};
        
        int x;
        int y;
        int z;
        
        srand((unsigned)time(NULL));
        
        //SORTEIA NUMEROS DE 1-8 PRA CADA VARIAVEL
        for(int i=0; i<300; i++){
    	
        x = rand() % 7;
        
        y = rand() % 8;
        
        z = rand() % 8;
        
        //CONCATENA POR ORDEM EM OUTRA VARIAVEL
        memset(&nomepronto[1], 0, sizeof(nomepronto[1]));
        strcat(nomepronto[1], nome1[x]);
        strcat(nomepronto[1], nome2[y]);
        strcat(nomepronto[1], nome3[z]);
        
        printf("\n\n%s %d - %d - %d ", nomepronto[1], x, y, z);
    }
    }

     

  2. Sou iniciante em C e estou criando um rpg, então elaborei o seguinte codigo que sorteia palavras contidas em 3 vetores: nome1, nome2, nome3, e concatena em nomepronto para formar nome de inimigos. O problema é que algumas vezes o primeiro nome nāo aparece, e outras sai caracteres estranhos. Acredito que tenha haver com o caractere nulo, mais nāo tenho ideia de como concertar isso:

    #include <stdio.h>
    #include <time.h>
    #include <stdlib.h>
    
    int main ()
    {
        char nomepronto[2][50];
        
        char nome1[8][50] = {"DRAGAO","LADRAO","REI","POLVO","MONSTRO","LEAO","HOMEM"};
        
        char nome2[8][50] = {" ESMAGADOR DE"," COMEDOR DE"," VENDEDOR DE"," CHUPADOR DE", " ARRANCADOR DE", " MANIPULADOR DE"," FURTADOR DE"," ADORADOR DE"};
        
        char nome3[8][50] = {" CABEÇAS", " TRIPAS", " OSSOS", " SANGUE", " OLHOS", " CACHORRO", " COBRAS", " DEMONIOS"};
        
        int x;
        int y;
        int z;
        
        srand((unsigned)time(NULL));
        
        //SORTEIA NUMEROS DE 1-8 PRA CADA VARIAVEL
        
        x = rand() % 8;
        
        y = rand() % 8;
        
        z = rand() % 8;
        
        //CONCATENA POR ORDEM EM OUTRA VARIAVEL
        
        strcat(nomepronto[1], nome1[x]);
        strcat(nomepronto[1], nome2[y]);
        strcat(nomepronto[1], nome3[z]);
        
        printf("\n\n%s", nomepronto[1]);
    }
     

     

    Screenshot_2016-11-08-19-55-13.jpg

    Screenshot_2016-11-08-19-57-40.jpg

×
×
  • Criar Novo...