vendredi 26 février 2016

Code to generate A-Z generates H, 72,

I am using the following code:

srand(time(NULL));
int r = rand() % 25 + 65;
char c = (char) r;
fprintf(stdout, "%c", c);
char d = (char) r;
fprintf(stdout, "%d", d);
char e = (char) r;
fprintf(stdout, "%e", e);
NSLog(@"%c");
NSLog(@"%d");
NSLog(@"%e");
_firstRandomLetter.text = [NSString stringWithFormat:@"%c", c];
_secondRandomLetter.text = [NSString stringWithFormat:@"%d", d];
_thirdRandomLetter.text = [NSString stringWithFormat:@"%e", e];

...to try and generate 3 letters from A to Z and display them. However, I get bizarre things such as 72 and ... as results. Everything displays fine.




Aucun commentaire:

Enregistrer un commentaire