Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

I am triing to use the rand() to send back a string

Status
Not open for further replies.
You need to generate a rand number in the range of the ASCII character set, then convert that number into a letter. Repeat for the required number of characters.

(A-Z = 65 - 90, a-7 = 97 - 122)

i.e.
for 1 letter,

Generate number between 0 & 57
Add 65 to that number
if number is > 90 and < 97, discard
char x = number;

For a string, do as above, but you need a counter into the char array i.e.

char x[10];

for (i = 0;i<10;i++)
{
Generate number between 0 & 57
Add 65 to that number
if number is > 90 and < 97, discard
x = number;
}

apologies for posting mostly text, but I am sure you get the idea.

K
 
Kalisto, thank you for the help. I am doing data structures and doing a program that is a two player black jack game. I am going to make the string a char set and will relate the number generated correspond to the character. Rich
 
Sorry, I don't really understand what you are asking here ?

If you are just telling me what you are doing, then I am glad I could help :)

If you have another question, please can you ask it again with an example (my brain is dead already, and I haven't been at work that long !)

K

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top