468,513 Members | 941 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,513 developers. It's quick & easy.

generating a random string

1
hello, help.

i'm trying to generate a random string of characters of user defined length, with or without repetitions. i've just started using C and have absolutely no idea what i'm doing.
Sep 3 '06 #1
1 3935
Banfa
9,056 Expert Mod 8TB
OK well use the following functions
  • fgets - to read input from the user (use the file stdin)
  • atoi or strtoul - convert user data to a binary number
  • malloc - to allocate data for the string, remember you will need to terminate the string with a NULL ('\0') character so allocate 1 more slot than the user requests.
  • [b]free - to free the the allocated data before the end of the program once you have finished with it
  • srand - to seed the random number generator, people often use the return value from time to get a seed value
  • rand - to get a random number, this will be in the range 0 - RAND_MAX and you will need to scale it to the range you require.

You will also need to know how arrays work.

I suggest you look all that up, then when you have made an attempt post it here and we will help you debug it.
Sep 3 '06 #2

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

21 posts views Thread by Andreas Lobinger | last post: by
7 posts views Thread by eric.gagnon | last post: by
3 posts views Thread by Peter Fox | last post: by
16 posts views Thread by Leon | last post: by
2 posts views Thread by Simon Wittber | last post: by
6 posts views Thread by Mike P | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.