miteigi-san 24 Newbie Poster

I just want to suggest that Daniweb add a 'save as draft' option when creating new posts.

I think it would be helpful to those who take a lot of time writing their posts, and to those who stop at the middle of writing to check ideas, but want to continue writing their post later on...

TrustyTony commented: Quite good idea +0
miteigi-san 24 Newbie Poster

Im only a beginner so I didn't know about that, but thanks anyway, at least now i know something like that existed. makes life more easier = ).

Thank you! at least someone noticed my post and helped me with it = ).

Nick Evan commented: That's the spirit! +12
miteigi-san 24 Newbie Poster

NOTE:
~this code is in c++
~you need not change anything in the code
~the commented lines are there just in case you want to see how the program works in real time - simply uncomment them and run the program, these commented lines are not necessary for the program to work
~code does not swap the characters of the string n times just to randomize
~string contents are shuffled character by character only
~the code is done with Code::Blocks

HOW THE CODE WORKS:
~the program asks user to input a string, then it outputs the shuffled version of the string
1. the program tells the user to enter a string
2. getline(cin,word); saves the string into string variable word
3. the length of the string is determined and saved to int variable x
4. srand is called so that the program will randomize differently for each instance you run the program
5. the while loop does the assigning of characters found in string variable word to temp
6. the resulting string temp is outputted so you can see the result of the shuffle

~further explanation for number 5
for example, you entered "twister"
twister is saved to string variable word
x is given the value of the length of the string variable word, which in this example, is 7 (seven)
in the loop,
temp is the string where we …

miteigi-san 24 Newbie Poster

why are you randomly accessing the file? if you are going to use the whole file i believe it would be faster to read the whole file into an array and then access the array at random points.

string array[256];  //  just a guess use whatever number you need to fit all of the words;
int i = 0;
fstream fin("test.txt"); // <-  this line opens the file
if (fin.fail())
{
       cout << "unable to open file.";
       return 0;
}
while (getline(fin, array[i]))
       i++;
fin.close()

with this you just access the array with your random number instead of accessing the file every time. also i don't see you opening the file associated with openWP so that is probably your problem

the opening of the file is in another function that calls that function~
and I dont think using the array will be convenient because the words will consume too much memory..
the words should be in the file so i could edit the file without using the program, and I dont need to load the array everytime i open the program...

miteigi-san 24 Newbie Poster

I'm still working on the same problem.
Im doing a text-twist code for c++ as part of our school requirement.
Last time, I'm having problems on delaying outputs using CLOCKS_PER_SEC and clock(), but thanks to some people, I solved that problem already.

Now, Im working on the game's play mode.
I SHOULD have a text file that contains all the words available/ all the words that can be used for playing my text-twist program. Right now, Im only using a substitute for it, ex: i put some text on the txt file just so i can test if the getline works.

So... the problem is getline.
Here's a part of my code

string getword(){
        /*this function will
        get a word from set of 50 words by using rand and seekg
        --use srand and rand to generate a number from 0-49
          --resulting number will be saved to int wordnum
        --wordnum then will be multiplied to a fixed number 20, which is the length or each line in the file "wordpool.txt"
            --take note that each line in the file contains a word and all its possible combinations, there are exactly 50 lines in the file, one line for each word.
        --using seekg, the cursor will be moved to the position of the word
        --getline will isolate that line (line that contains the word and all its combinations) into an array called "wordset"
        --file will be closed since leaving it open will not be necessary
        --and …
miteigi-san 24 Newbie Poster

thanks.
i figured it out too.
im just confused by the innermost while since its my first time seeing a while without contents.

miteigi-san 24 Newbie Poster

I've been reading sites that talk about clock() but I don't really get an answer by doing that. I mean, I still need to confirm and know some more stuff. I hope you could help me...

Here's what i would like to know:
1] what does the value returned by clock() mean?
---system clock ticks? if yes, what exactly is system clock ticks
compared to wall clock/ wristwatch clock?


2] what does the value returned by CLOCKS_PER_SEC mean?
---is its value always 1000? and is it how much the clock() value increases in a second?


3] how does these two codes differ in how they function?
---from http://www.daniweb.com/forums/thread120452.html#

if (clock() > FiveSecondsLater)
      {
                // Do whatever it is you want to do.
      }

and this one

void wait (float seconds)
      {
      clock_t EndTime = seconds * CLOCKS_PER_SEC;
                while (EndTime > clock())
                {
                // this will loop until clock() equals EndTime
                }
      }

---i mean, aren't they the same wait function?


4] does the first code need a loop(outside) for it to become a wait function? and if yes, what condition shall i put to it?

im trying to make dots appear in succession
and im using codeblocks

from this code...

/* clock example: countdown */
#include <stdio.h>
#include <time.h>
  int n;
void wait ( int seconds )
{
  clock_t endwait;
  endwait = clock () + seconds * …
Nick Evan commented: Excellent first post! +12