Hi al, Ive played with C like 5 or 6 years ago but i completely forgot how it works untill recently i'm doing it for a fun project. Anyway heres my code. randstr() will return a 6 char random string. I can printf the results on the randstr() functoin,but whenever i pass the value back to main() to be prinft. i get a lot of weird values. Englighten me!! thanks in advance
Code:
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <string.h>
char *randstr()
{
char tempstr[6];
char rnd;
/* Set evil seed (initial seed) */
srand( (unsigned)time( NULL ) );
for (int i = 0; i < 6; i++) {
rnd = ((float) rand()/RAND_MAX) * 25 + 97;
tempstr[i] = rnd;
}
tempstr[6] = '\0';
// printf("%s\n",tempstr);
return tempstr;
}
int main()
{
printf("%s",randstr());
return 0;
}