471,873 Members | 2,029 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,873 software developers and data experts.

generating a random string

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 4069
9,065 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
reply views Thread by zermasroor | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.