What happened to the Messenger Plus! forums on msghelp.net?
Shoutbox » MsgHelp Archive » Skype & Technology » Tech Talk » [C help] how to...

[C help] how to...
Author: Message:
crank
Full Member
***

Avatar
Failed to come back here :(

Posts: 304
Reputation: 17
35 / Male / Flag
Joined: Mar 2004
Status: Away
O.P. Huh?  [C help] how to...
I'm working on a new version of QTSender (look over here)

Here's my question:
How do I output a random line from a text file with a command.
code:
This is the content of hello.txt in the folder C:\...\plugins\QTSender\.

\x03#0000FFHello there!
\x03#0000FFHey you!
\x03#0000FFHello! How are you?
\x03#0000FFHey my friend!
\x03#0000FFHello buddy!


I know the formatting will work the only thing I'm wondering about is how to load it.
EXAMPLE:
You type /xQThello

and it outputs:
Hello buddy!

I'm working in C.

This post was edited on 06-10-2004 at 02:51 PM by crank.
I haven't been active here in ages.
If you're wondering who i am, read my reputations. I used to make plugins, skins and spam the IRC channels here back in the good old days before Windows Live.
06-10-2004 02:32 PM
Profile E-Mail PM Web Find Quote Report
RaceProUK
Elite Member
*****

Avatar

Posts: 6073
Reputation: 57
39 / Male / Flag
Joined: Oct 2003
RE: [C help] how to...
code:
int <result> = rand() % <out-of>;
The rand() function returns a number from 0 to MAX_INT (32,767 I think). By using the modulo division operator %, you can replace <out-of> with an integer e.g. use 10 to get a random number from 0-9 inclusive.
[Image: spartaafk.png]
06-11-2004 10:09 AM
Profile PM Web Find Quote Report
crank
Full Member
***

Avatar
Failed to come back here :(

Posts: 304
Reputation: 17
35 / Male / Flag
Joined: Mar 2004
Status: Away
O.P. RE: [C help] how to...
quote:
Originally posted by raceprouk
code:
int <result> = rand() % <out-of>;
The rand() function returns a number from 0 to MAX_INT (32,767 I think). By using the modulo division operator %, you can replace <out-of> with an integer e.g. use 10 to get a random number from 0-9 inclusive.

I know that I'm just wondering how to get it from the file...
I haven't been active here in ages.
If you're wondering who i am, read my reputations. I used to make plugins, skins and spam the IRC channels here back in the good old days before Windows Live.
06-11-2004 01:26 PM
Profile E-Mail PM Web Find Quote Report
RaceProUK
Elite Member
*****

Avatar

Posts: 6073
Reputation: 57
39 / Male / Flag
Joined: Oct 2003
RE: [C help] how to...
Ah right. In that case, what I would do is read each line of text from the file into an array, then use the random number generated to index the array.
Reading the file in: I would use a while loop, checking for an EOF. Of course, to make the array in the first place, the number of lines in the file would need to be known.
It may be worth seeing if C++ has a class similar to Java's ArrayList, which implements an expandable array of objects.
[Image: spartaafk.png]
06-11-2004 01:30 PM
Profile PM Web Find Quote Report
crank
Full Member
***

Avatar
Failed to come back here :(

Posts: 304
Reputation: 17
35 / Male / Flag
Joined: Mar 2004
Status: Away
O.P. RE: [C help] how to...
I never worked with files before so some extra info would be nice...
I'm not working on the programm till next week tough...

(exams)
I haven't been active here in ages.
If you're wondering who i am, read my reputations. I used to make plugins, skins and spam the IRC channels here back in the good old days before Windows Live.
06-11-2004 01:38 PM
Profile E-Mail PM Web Find Quote Report
RaceProUK
Elite Member
*****

Avatar

Posts: 6073
Reputation: 57
39 / Male / Flag
Joined: Oct 2003
RE: [C help] how to...
I've never worked with files in C/C++ either, so I'll refer you to the rather good (if a little hard to use) MSDN Website. Just search for 'file reading C' and you should get some relevant results.

Edit: OK, so that search doesn't help much. Searching for 'fopen' may work better.
Also, make sure you are reading Visual C++ documentation.

This post was edited on 06-11-2004 at 01:43 PM by RaceProUK.
[Image: spartaafk.png]
06-11-2004 01:41 PM
Profile 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