Below is what I tried. I can only use getchar/putchar for IO. How would I go about randomly generating 40 uppercase letters? I know that uppercase letters are 65 - 90 on the ASCII table, just not sure how to execute this properly.
Thanks.
1 2 3 4 5 6 7 8 9 10 11 12 13 14
void getRandomStr(){
char str[40];
int i;
for (i = 0; i < 40; i++){
char c = rand() % 26;
str[i] = c;
}
}
void getRandomStr(){
char str[40];
int i;
for (i = 0; i < 40; i++){
char c = (90 - (rand() % 26));
str[i] = c;
}
for (i = 0; i < 40; i++){
putchar(str[i]);
}
}
Just need to see how I can replace the printf() with putchar(). Working on it now.
Edit: guess you just replace the printf() with putchar(str[i]); Seemed easy enough.
Seems a bit obfuscated doing it that way or even char c = 'Z' - rand() % 26; which is equivalent to what you are doing. Most people would start from the first letter and add on to it instead of starting from the back and counting down.