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

here is what I came up with:

the problems I fixed:

  • you were trying to delete the cptr array itsself. not the things inside it, so I added a loop to do this
  • array values start at 0 so I changed some loops or you would get segmentation faults trying to access the item above the one you wanted (eg 2 items you would have instead of 0 and 1, printed item 1 and 2 (and 2 would not exist!!))
  • maybe not necessarily, but I added memsets to make sure the string terminates (if its filled with rubbish it may think its longer than it actually is)
  • removed system("pause") in favour of cin.get() (does the same thing but cin.get() is less resource heavy ect..)

this now compiles ok with minGW and runs fine for me. see if it works for you.

#include<iostream>
#include<cstring>

using namespace std;


class city
{
      protected:

		char *name;
		int len;

      public:
			void getname(void)
			{
				char *s;
				s= new char[30];
				memset(s, '\0', sizeof(char) * 30);
				cout<<"Enter city name: ";
				cin>>s;
				len= strlen(s);
				name= new char[len+1];
				strcpy(name,s);
			}
			void printname()
			{
				cout<<name<<"\n";
			}
};
int main()
{
    city *cptr[10];
    int n = 0;
    int option;
    do
    {
        cptr[n]= new city;
        cptr[n]->getname();
        n++;
        cout<<"Do you want to enter one more name?\n";
        cout<<"(Enter 1 for yes 0 for no):";
        cin>>option;
	}
	while(option);

    cout<<"\n";

    for(int i=0; i<n; i++)
    {
		cptr[i]->printname();
	}

	for(unsigned short i = 0; i < n; ++i)
	{
		delete cptr[i];
	}

        
	cout<< "\npress …
MattyRobot 22 Junior Poster in Training

pleased I could help :)

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

or the generic #wrapper * applies to anything inside wrapper rather than specificly setting the opacity for every child element.

MattyRobot 22 Junior Poster in Training

no offence but the code is a little messy.

there were a few mistakes where some elements were not closed and there was not starting <html> tag

I have indented the code and fixed the issues and it renders correctly in firefox (i checked the opacity with firebug :P)

<html>
	<head>
		<style type="text/css">
			#wrapper {
				width: 860px;
				margin-left: auto;
				margin-right: auto;
				padding-right: 5px;
				padding-left: 5px;
				background: #ffffff;	
				opacity: 0.8;
				filter:alpha(opacity=80);
				-moz-opacity:0.8;
				filter:progid:DXImageTransform.Microsoft.Alpha(Opacity=80);
				-khtml-opacity: 0.8;
				-ms-filter: “progid:DXImageTransform.Microsoft.Alpha(Opacity=80)”;
				}
				
				
			#wrapper * {
				opacity: 1.0;
				filter:alpha(opacity=100);
				-moz-opacity:1.0;
				filter:progid:DXImageTransform.Microsoft.Alpha(Opacity=100);
				-khtml-opacity: 1.0;
				-ms-filter: “progid:DXImageTransform.Microsoft.Alpha(Opacity=100)”;
				}
		</style>
	</head>
	
	<body>

		<div id="wrapper">

			<div id="left">
				<img src="images/logo.jpg"  width="163" height="132" class="des_logo" />
				 
				<ul class="side_nav">

					<li class="main_nav">
						<a href="#">Company Profile<br/> 
						<span class="main_nav_2">A bit about our company</span></a>
					</li>

				</ul>
			 
			</div>
			<div id="right"> 
				<div id="top">
					<div class="top_nav">

						<ul>
							<li><a href="#"> Home</a></li>
							<li><a href="#"> Contact</a></li>
						</ul>
						
					</div>
					<div class="top_tels">Bristol: <span class="tels">000000000</span> | Bath: <span class="tels">00000000</span> | Mendip: <span class="tels">00000000</span></div>
				</div> 

				<div id="flash">
					<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,19,0" width="645" height="250">
						<param name="movie" value="header_v2_3.swf" />
						<param name="quality" value="high" />
						<embed src="header_v2_3.swf" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" width="645" height="250"></embed>
					</object>
				</div>

				<div id="page_headers">Home</div> 
				<div id="content">
				   <p>here is some content text</p>
				</div>

			</div>

			<div id="footer">

				<div class="address">
					<p> address</p>
					<div class="footer_tels">
						<p> Tel: 000000</p>
					  
					</div>
					  
				</div>
			</div> 
		</div>
	</body>
</html>
MattyRobot 22 Junior Poster in Training

could I see the html as well as there doesn't appear to be anything wrong with the css

MattyRobot 22 Junior Poster in Training

no it works for css i tried it and it did work
the #wrapper * means everything inside wrapper
so wrapper opacity 80%
everything inside 100%

MattyRobot 22 Junior Poster in Training

this might work:

#wrapper {
background: #ffffff;	
opacity: 0.8;
filter:alpha(opacity=80);
-moz-opacity:0.8;
filter:progid:DXImageTransform.Microsoft.Alpha(Opacity=80);
-khtml-opacity: 0.8;
-ms-filter: “progid:DXImageTransform.Microsoft.Alpha(Opacity=80)”;
}

#wrapper *
{
opacity: 1;
filter:alpha(opacity=100);
-moz-opacity:100;
filter:progid:DXImageTransform.Microsoft.Alpha(Opacity=100);
-khtml-opacity: 0.8;
-ms-filter: “progid:DXImageTransform.Microsoft.Alpha(Opacity=100)”;
}

the * means everything

MattyRobot 22 Junior Poster in Training

I am getting the error:
There is no disk in the drive. Please insert a disk into drive \Device\Harddisk1\DR1.

I have already read the answers of previous posts, but none of them fit to my situation.

I am running code blocks from a usb stick. When I start debugging I get the error. not just once, it never goes away and the debugger never starts. (I have to use task manager to close it and make the error stop popping up)

I have had the error elsewhere but I have always been able to click it away so it hasn't been a problem

here are the drives in my computer:

OS C: hard drive not hidden
EXTERNAL X: external hard drive not hidden

DVD-RW D: not hidden
RemovableDisks E: F: G: H: all hidden
my usb stick R: not hidden

MattyRobot 22 Junior Poster in Training

putting it outside of main() means that it isn't called when the program is run.
and I think the errors happened because the function uses argc and argv which are not in the global scope (they can only be used inside main())

well thats my guess anyway :)

MattyRobot 22 Junior Poster in Training

it might be because glutInit is outside of main?
(if that's how your actual code looks)

MattyRobot 22 Junior Poster in Training

I am trying to move a project from CodeBlocks to visual c++. (it compiles fine using minGW)
I am using the 2010 express version.
when I compile the projectusing VC++ I get the errors below.
I have done some research and it is comming from including windows.h.
to test this I made a simple project (default console project) and included windows.h and I got the same errors.

does anyone know why they are happening?

1>------ Build started: Project: test of and operator, Configuration: Debug Win32 ------
1> test of and operator.cpp
1>c:\program files (x86)\microsoft sdks\windows\v7.0a\include\driverspecs.h(142): error C2008: '$' : unexpected in macro definition
1>c:\program files (x86)\microsoft sdks\windows\v7.0a\include\driverspecs.h(294): error C2008: '$' : unexpected in macro definition
1>c:\program files (x86)\microsoft sdks\windows\v7.0a\include\driverspecs.h(295): warning C4005: '__' : macro redefinition
1> c:\program files (x86)\microsoft sdks\windows\v7.0a\include\driverspecs.h(142) : see previous definition of '__'
1>c:\program files (x86)\microsoft sdks\windows\v7.0a\include\driverspecs.h(308): error C2008: '$' : unexpected in macro definition
1>c:\program files (x86)\microsoft sdks\windows\v7.0a\include\driverspecs.h(309): warning C4005: '__' : macro redefinition
1> c:\program files (x86)\microsoft sdks\windows\v7.0a\include\driverspecs.h(295) : see previous definition of '__'
1>c:\program files (x86)\microsoft sdks\windows\v7.0a\include\driverspecs.h(312): error C2008: '$' : unexpected in macro definition
1>c:\program files (x86)\microsoft sdks\windows\v7.0a\include\driverspecs.h(313): warning C4005: '__' : macro redefinition
1> c:\program files (x86)\microsoft sdks\windows\v7.0a\include\driverspecs.h(309) : see previous definition of '__'
1>c:\program files (x86)\microsoft sdks\windows\v7.0a\include\driverspecs.h(316): error C2008: '$' : unexpected in macro definition
1>c:\program files (x86)\microsoft sdks\windows\v7.0a\include\driverspecs.h(317): warning C4005: '__' : macro redefinition
1> c:\program files (x86)\microsoft sdks\windows\v7.0a\include\driverspecs.h(313) : …

MattyRobot 22 Junior Poster in Training

hi again:).
I'm not 100% sure what you mean by

window's size in the view port

but here is my resize handling code

void Window::UpdateGLProjection()
{
	GetDimensions();
	if(fullscreen == true)
    {
        glViewport(0, 0, ScreenWidth, ScreenHeight);
    }
    else
    {
    	if(ClientHeight == 0)
    	{
    		ClientHeight = 1;
		}
		glViewport(0, 0, ClientWidth, ClientHeight);
	}

	glMatrixMode(GL_PROJECTION);
	glLoadIdentity();

	if(dimensions == 2)
	{
		glOrtho(0, WorldWidth, WorldHeight, 0, -1, 1);
	}
	else if(dimensions == 3)
	{
		gluPerspective(45, float(ClientWidth) / float(ClientHeight), 0, 100);
	}
	else
	{
		MessageBox(NULL, "Invalid Number Of Dimensions", "ERROR", MB_OK | MB_ICONEXCLAMATION);
	}

	glMatrixMode(GL_MODELVIEW);
	glLoadIdentity();

return;
}

as you would expect, when I use glOrtho, everything is stretched, but not when using gluPerspective

(50 posts!!!)

MattyRobot 22 Junior Poster in Training

is it possible to stretch a 3D scene in openGL?

I know it is possible in glOrtho() but how would I make a 3D scene stretch.

for example if I rendered a cube, in the middle of a window, and then made the window longer, instead of the cube stretching, I would see more to the left and right of it, and I do not want this :(.

MattyRobot 22 Junior Poster in Training

yep :).
i texture mapped the image onto two triangles.
and i made the images object oriented.

class Image
{
// Attributes
public:
    std::string path;
    std::string extension;

    GLuint texture_num;

// Methods
public:
    Image() {};
    ~Image() {};
    bool load(std::string FileName);
    void reload();
};

and I added a reload function for when the window goes into full screen mode and shuts down opengl.

MattyRobot 22 Junior Poster in Training

I did:).

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

MattyRobot 22 Junior Poster in Training

I have made my own image load function that reads the file extension and loads the image with the appropriate method. but at the moment it can only load bitmaps. and i know now why the image wasn't loading properly, the image was 8 bit but the function was reading it assuming it was 24 bit. how could i discard the pixels that are a certain colour (the colour around the edge)?

MattyRobot 22 Junior Poster in Training

thank you :) i shall get to work and report back when (if) it works. and i wont copy + paste, i will only copy the method.

MattyRobot 22 Junior Poster in Training

that's for Microsoft visual studio though, i use code blocks. I copied glut.h to include/GL/' but in lib, where it tells me to put glut32.dll, glut32.lib and glut.def the folder currently only contains .a and .o files, should I Put them there anyway?

MattyRobot 22 Junior Poster in Training

yeah I know but I don't know how to download it???

MattyRobot 22 Junior Poster in Training

thank you that would be great:icon_cheesygrin:.

and no, I don't have glut.h. I wouldn't use it (I make my windows with the win32 api) but its a pain when I'm trying to see how other peoples code works

MattyRobot 22 Junior Poster in Training

i cant compile or run their code straight from downloading it. i get the error:

This application has failed to start because glut32.dll was not found. Re-installing the application may fix this problem.

but i did include "texture.h" in my own project and followed the instructions and it loads without errors but the image is very distorted

MattyRobot 22 Junior Poster in Training

well, I copied and pasted the code first to see if it worked before writing it myself and I didn't get any compiler errors, that's a start. but I don't know if it will work yet.

what are the advantage of using tga files?

and its nice you remember me :)

MattyRobot 22 Junior Poster in Training

what would be a good way to load images to use for texture mapping in opengl?

I have looked at tutorials such as nehe lesson 6 and some other resources but they all use something old and depreciated that I cant compile.

MattyRobot 22 Junior Poster in Training

ok

MattyRobot 22 Junior Poster in Training

would there be anything wrong with making an includes.h which has all of the .h files my project needs to link to.
or is it better to link to them when needed?

MattyRobot 22 Junior Poster in Training

yes I will try that...
done, it works exactly the same, but with less code so thanks.
but the problem is the same, am I doing it right?

MattyRobot 22 Junior Poster in Training

I have been trying to get world coordinates of the cursor position for a program by:

  1. getting the top and left position of the client of the window
  2. getting the global position of the cursor (GetCursorPos())
  3. cursor x - client left and cursor y - client top
  4. zoom x and y = client width and height / 100 (the openGL world size in the program)
  5. divide cursor pos x and y by zoom x and y

I made it up myself so it may have major errors.
it doesn't work, but am I along the right lines or is there an obvious reason for it not working?

MattyRobot 22 Junior Poster in Training

thats good because im only doing 2d at the moment, but and how do i 'adjust'?

MattyRobot 22 Junior Poster in Training

in openGL how can I make the left of the screen = 0 and the right to = 10 or somthing, and the top = 0 and the bottom = -10. because i dont like working with numbers only ranging from -1.0 to 1.0. i read here that the coordinate system could be whatever you wanted it to be but so far i have not found a command that changes it.

MattyRobot 22 Junior Poster in Training

good???

MattyRobot 22 Junior Poster in Training

sorry you didnt make it clear what you wanted.
if you want to use a graphics library then open gl and glut would be quite easy. again im not sure this is what you want but check out http://www.videotutorialsrock.com/
also maybe wxWidgets

MattyRobot 22 Junior Poster in Training

well if you want to make guis for windows the you can use:
http://www.winprog.org/tutorial/ its quite tricky to get the hang of but its ok :)

MattyRobot 22 Junior Poster in Training

what is the difference between a #pragma comment and a regular one?

MattyRobot 22 Junior Poster in Training

I have been trying for ages to get glut working (in code blocks)
and now it works... sort of. I can compile and run applications but it comes up with several warning: ignoring #pragma comment errors in glut.h. I got the glut.h file from here. because all other downloads of glut I used didn't work at all. why am I having this trouble with installing glut?