samedi 10 décembre 2016

Character array with no spaces, sometimes returns a space when taking a random member of it

So I made a simple program that takes random from my Str[] array of characters. Code:

#include <iostream>
#include <cstdlib>

using namespace std;

int main() {
    char Str[] =
    "0123";
    while(true) {
          cout << Str[rand()%sizeof(Str)];
     }
}

At line 8 the array members are defined and as you can see there are no spaces in that declaration. But if so, why does my console output contains several spaces? This is a random line i picked from the output:

0 2 3132320 3  1 21  210 31123 01021221113 3031031 01 00331232331 21 32002 0




Aucun commentaire:

Enregistrer un commentaire