By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,320 Members | 2,239 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,320 IT Pros & Developers. It's quick & easy.

generating a random string

P: 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
Share this Question
Share on Google+
1 Reply


Banfa
Expert Mod 5K+
P: 8,916
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.