MattyRobot 22 Junior Poster in Training

mark as solved :) + glad i could help

MattyRobot 22 Junior Poster in Training

looking on msdn again. http://msdn.microsoft.com/en-us/library/aa904305(v=vs.71).aspx

you could read the whole stream into a string using ReadToEnd then use String.Split and pass '\n' to it ('\n' == New Line)

MattyRobot 22 Junior Poster in Training

you mean you want the output tokenized into lines?

MattyRobot 22 Junior Poster in Training

saw that Narue posted first but it still adds a bit more info

no. srand sets the seed, it doesnt generate random numbers. the seed is a number that rand uses to generate random numbers.

rand potentially generates large numbers but some maths is all you need to put some boundaries on it:

x = rand() % 10;

the % sign is modulus, it calculates the remainder from the division (divide by 10 in this case). so thinking about it, this means that x could only equal a number from 0 - 9.

about time(0), http://cplusplus.com/reference/clibrary/ctime/time/
time takes an argument which tells it where to store the time, if it is 0, then it returns it.

MattyRobot 22 Junior Poster in Training

good point about the pointer. good point about me completing the whole thing (I got a bit carried away :)). in my defence about the extra parameter, I was copying what they had done for their length function, and its harder to overload without the extra parameter.

[EDIT]: oh wait, not aimed at me. but the bit about overloading still stands (but then i suppose you could use copy() and copy_step2(). my advice, dont use a recursive function where a loop would suffice :))

out of interest mike. how would you differentiate between the 'base' call to copy and the iterating call to copy

MattyRobot 22 Junior Poster in Training

looking on msdn (http://msdn.microsoft.com/en-us/library/system.io.streamreader.readtoend.aspx)
StreamReader has a ReadToEnd function.

is this what you were looking for?

MattyRobot 22 Junior Poster in Training

OK. I tried (and failed) to keep to the same code style as the one you had. (and cleaned up with some const correctness :) )
I came up with this (included main() to show how to use)

the RecursiveCopy function with no int argument checks to see if old_str is valid and if new_str is valid. it then calls the RecursiveCopy function with the int argument and it iterates through old_str and copies the data char by char into new_str

hope you like it :)

PS:
how do you feel about letting a 15 year old do your homework :) (if it is homework)

#include <windows.h>
#include <iostream>
using std::cout;


int length(const char* str, int l){
	int len=0;
	if(str[l]){
		len = length(str,l+1);
	} else {
		return l;
	}
	return len;
}

int length(const char* str){
	if(str == NULL){
		return 0;
	}else{
		return length(str, 0);
	}
}




void RecursiveCopy(const char* old_str, char* new_str, int iterator){
	if(old_str[iterator])	// stops at \0
	{
		new_str[iterator] = old_str[iterator];
		RecursiveCopy(old_str, new_str, iterator + 1);
	}
	else
	{
		new_str[iterator] = '\0';	// need to terminate the copied string
		return;
	}
}

// assumes new_str is allocated
bool RecursiveCopy(const char* old_str, char* new_str){
	if(old_str == NULL){
		cout << "Could not copy, string is empty\n";
		return false;
	}else if(length(new_str) < length(old_str)){
		cout << "Could not copy, destination is too small to fit the origional string into\n";
		return false;
	}else{
		RecursiveCopy(old_str, new_str, 0);
		return true;
	}
}

int main()
{
	char* test = …
MattyRobot 22 Junior Poster in Training

a pointer (or reference) is like a sign saying "this is where ... is".
as you (should) know any variable you create is allocated in ram and given an address so the program knows where to find it.

if you point pointer to a variable then you can use the pointer as a variable its self eg you can print it with cout, point it to somewhere else but you can also access the variable through it. a reference is like a pointer but you cant treat it as a variable. you can only access the data it points to (so think of (type& x) as an alias and (type* x) as a sign showing the function where to find x)

so if you have void function(type x) { return; } and you call it like so function(AnObject); a copy is given to the function


sorry if im going a bit too in depth and ask if u don't get something. and don't forget to mark as solved :)

MattyRobot 22 Junior Poster in Training

srand sets the seed for the random number generator (it takes the number you put in and passes it through a logarithm which generates a pseudo(fake, not totaly random) set of numbers).
setting it by time(), you almost never get the same seed twice and so GREATLY improves randomness.

MattyRobot 22 Junior Poster in Training

i think it is becuase you are passing copies of the nodes to the setRightChild setleftChild functions. not references (or pointers)
so instead of this

void Node::setleftChild(Node n1)
{
	leftChild=&n1;
}
void Node::setRightChild(Node n2)
{
	rightChild=&n2;
}

try

void Node::setleftChild(Node* n1)
{
	leftChild=n1;
}
void Node::setRightChild(Node* n2)
{
	rightChild=n2;
}

...

n3.setRightChild(&n4);
n3.setleftChild(&n5);

in debug mode maybe the copies are not deleted after the function returns and so there is no error. to test this see if the addresses of n3 and n5 match the pointers to them in n4

MattyRobot 22 Junior Poster in Training

well it depends whether the fan is controlled by the computer or whether it just uses the usb power

if its just controlling the power there is a post here:
http://stackoverflow.com/questions/1925237/control-usb-ports-power

if it has a driver and or api then either use the api or
http://sourceforge.net/apps/trac/libusb-win32/wiki

and here is some general usb interface advice:
http://www.beyondlogic.org/index.htm#USB

hope it helps

MattyRobot 22 Junior Poster in Training

this is an idea I had. remove everything above 0 like you did. then convert the decimal bit to a string. then get the length of the string.

#include <iostream>
#include <string>
#include <sstream>

int DecimalPlaces(double test)
{
	double JustDecimals = test - (int) test;

	std::stringstream converter;

	converter<< JustDecimals;

	std::string StringForm(converter.str());

	return StringForm.length() - 2 /* -2 characters for the 0. */;

}

int main()
{
	std::cout<< "decimal places in " << 0.235987 << " " << DecimalPlaces(0.235987);
        // returns 6 which is right
}

this works but it does not test exceptions like if the input is not a decimal then dont minus the 2 otherwise DecimalPlaces(3) == -2

oh and the maximum number of decimal places seems to be 6 (with one number to the left of the decimal point).

MattyRobot 22 Junior Poster in Training

don't you thing he should know more about c++ first though?

MattyRobot 22 Junior Poster in Training

Thats what I was trying to tell him but he wants to go straight onto graphics!!!

MattyRobot 22 Junior Poster in Training

got it.
before you use remove, you have to use cipher.close() and plainText.close()

MattyRobot 22 Junior Poster in Training

http://www.daniweb.com/forums/thread510.html
maybe
and i compiled it and it doesn't work for me either