i dont know how to random select a word in c . a big help is highly appreciated .. tnx :)
for example the words are Ana,Lorie and Denise . how to random select from those words ?
theCompiler
0
Light Poster
Recommended Answers
Jump to PostHow are those words stored? Do you know about srand() and rand()? Are you just selecting a single word, or do they need to be randomly ordered?
I'd start by storing the words in an array and then using rand() to get a random index into the array. This …
Jump to PostOkay, so you're selecting a single word. Have you tried my suggestion or done any research based on my previous post?
Jump to PostGood god, you're helpless. Didn't I point you toward rand()?
string[] words = {"ANA","LORIE","DENISE"}; puts(words[rand() % 3]); /* Print a random word */
You're clearly not putting any effort into helping yourself, so that's the end of my attempt to assist.
Jump to PostLet me guess, you're coming from a Java background? I suggest you get a book on C and actually read it before trying to type random code. Though I'll take some blame for being lazy and not correcting your broken syntax for the words array. Here's your corrected code:
Jump to PostStart at Narue's first post. The answer is there. You just have to look it up.
All 17 Replies
Narue
5,707
Bad Cop
Team Colleague
muktigeek
commented:
what is wrong in my code..???
-1
theCompiler
0
Light Poster
Narue
5,707
Bad Cop
Team Colleague
theCompiler
0
Light Poster
Narue
5,707
Bad Cop
Team Colleague
theCompiler
0
Light Poster
Narue
5,707
Bad Cop
Team Colleague
theCompiler
0
Light Poster
theCompiler
0
Light Poster
WaltP
2,905
Posting Sage w/ dash of thyme
Team Colleague
muktigeek
-8
Newbie Poster
WaltP
commented:
Offering full code is not acceptable.
-4
muktigeek
-8
Newbie Poster
Narue
5,707
Bad Cop
Team Colleague
muktigeek
-8
Newbie Poster
Narue
commented:
Maybe you should learn C properly and then you can stop hoping.
-4
theCompiler
0
Light Poster
Narue
5,707
Bad Cop
Team Colleague
theCompiler
0
Light Poster
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.