What happened to the Messenger Plus! forums on msghelp.net?
Shoutbox » MsgHelp Archive » Skype & Technology » Tech Talk » c++ help

c++ help
Author: Message:
Muss
Former Moderator
*****

Avatar
This Is The Start To A New Era

Posts: 1349
Reputation: 8
39 / Other / –
Joined: Apr 2002
O.P. c++ help
I am needing to RANDOMLY inport a string from a txt file.


I know how to get strings, single lines, single characters etc in order, but I have no idea how to jump to a random place, and get that entire word.


The way the txt file is set up is:

Word1
Word2
Word3
Word4
Word5
etc

So basically, the word, \n, another word, \n etc



Anyone able to help me with that?

[edit]

Also, I would prefer it if the person could explain why you do what, instead of just a straight code paste. I would find it alot more useful to understand why I am doing what, instead of blindly following :P


Cheers
Muss

This post was edited on 05-29-2004 at 07:40 AM by Muss.
05-29-2004 07:32 AM
Profile E-Mail PM Web Find Quote Report
Mike
Elite Member
*****

Avatar
Meet the Spam Family!

Posts: 2795
Reputation: 48
32 / Male / Flag
Joined: Mar 2003
RE: c++ help
If i understand correcly you want to get the text of a line from a txt file eh?
Well what i would do in vb:
Put the text file in a string...
Find how many lines the text file has so i can have a random number from 1 to the lines of the file.
Then use split() on the string that has the text and in the ()s put the random generated number
And get the final result.

Hopes this helps you! :)
Good luck :wave:

Btw i posted what i would do in vb, not in C++...
YouTube closed-captions ripper (also allows you to download videos!)
05-29-2004 08:36 AM
Profile E-Mail PM Web Find Quote Report
Muss
Former Moderator
*****

Avatar
This Is The Start To A New Era

Posts: 1349
Reputation: 8
39 / Other / –
Joined: Apr 2002
O.P. RE: c++ help
Well that doesn't help then :refuck:



Anyway I fgured out A way to do it, probably isn't very efficient, but it works well enough.


Generate random number
Enter For loop that loops until 'i' = the random number, and increment 'i'

In the loop read in a line of the text.

'i' then gets incremented, and is checked if it is = to the random number

if it isn't, we carry on the loop and the next line of text is read.


That happens until 'i' = the random number.


And thus have a semi random word :P



(used the srand time random thingy, so it generates a random number in relation to the time since some date, so it is basically truely random :P)


Thanks for attempting to help mike :P
05-29-2004 08:52 AM
Profile E-Mail PM Web Find Quote Report
« Next Oldest Return to Top Next Newest »


Threaded Mode | Linear Mode
View a Printable Version
Send this Thread to a Friend
Subscribe | Add to Favorites
Rate This Thread:

Forum Jump:

Forum Rules:
You cannot post new threads
You cannot post replies
You cannot post attachments
You can edit your posts
HTML is Off
myCode is On
Smilies are On
[img] Code is On