mardi 6 septembre 2022

Printing symbols after random function

I made a program that involves a lot of randomization.

It all works fine, except for array number 5 char a5, which includes 2 strings. There's a 5% chance of any of them appearing.

Once I execute my program, random symbols appear once in a while, if I launch it enough times, I hear the "Critical stop" error sound but no visible error.

My program has an input loop to prevent me from launching it again, which I'll keep here for ease of use.

Here's the minimal code:

#include <stdlib.h>
#include <stdio.h>
#include <time.h>
#include <windows.h>

main(){
    srand (time(NULL));
    int j, v;
    char i, mlt [6], a5[2][6] = {" x2", " x3"}; 
    do{ 
    system ("cls");
        for (j=0; j<10; j++){
            
            v = rand () % 95;
            char* b4[6] = {a5[v]};
            char mik[10] = (" ");
            
            strcpy (mlt, mik);
            strcat (mlt, *b4);
            printf (" %s\n", mlt);
        }
    printf ("Press 'n' to exit... ");
    scanf (" %s", &i);
    }
    while (i!='n' && i!='N');
}

Here's a screensnip example of a random launch (on my normal program):

output of normal code and a symbol




Aucun commentaire:

Enregistrer un commentaire