chrjs 42 Junior Poster in Training

No he means not agree because of the following line:

cin >> input[1] >> input[2] >> input[3] >> input[4] >> input[5];

This is saying that the array has up to 6 elements but it is defined as int input[5]. This means that calling input[5] will cause the program to crash because it is outside the bounds of the array. It should be this:

cin >> input[0] >> input[1] >> input[2] >> input[3] >> input[4];

Also, using this

int something;
   cin>>something;

is dangerous because if the user enters a character instead of an int the program will freak out.

Um, no. Ancient Dragon said "The parameters to the function in lines 5 and 27 to not agree." However, you said that he is using "not agree" to refer to the line "cin >> input[1] >> input[2] >> input[3] >> input[4] >> input[5];", which is line 18.

chrjs 42 Junior Poster in Training

By "not agree" he meant that the parameter at line 5 is an int and at line 27 it is an array of ints. That is probably what caused the undefined reference error.

chrjs 42 Junior Poster in Training

When it comes to compilers for linux, gcc is the most common, and it comes installed with ubuntu.

chrjs 42 Junior Poster in Training

You could try casting the wxString to a cstring and using a function like strcmp to compare the strings. Or maybe you could do something like if (s == wxString("Foobar")) I am not too familiar with wxwidgets, so I am not exactly sure what will work, but those seem like plausible options.

chrjs 42 Junior Poster in Training

Well, I found that I needed to change line 32 to return !(tx ^ x); , but the program doesn't work for negative numbers. It would be appreciated if anyone could give me an idea on how to account for the sign in this problem.

chrjs 42 Junior Poster in Training

I am not sure what you mean by "gaming terms" or "how does that translate over to online gaming", but it is not entirely right, technically it would be

...
-object file
-linker
-executable

there is also the debugging processes, but that doesn't really follow a linear order like the rest.

chrjs 42 Junior Poster in Training

I believe that on a 32-bit machine 1 assembly command is equal to 32 bits (4 bytes), and on a 64-bit machine 1 assembly command is equal to 64 bits (8 bytes), etc. I am not exactly sure if that is right, but I think it is.

chrjs 42 Junior Poster in Training

NCTKID1, what is the purpose of your three posts on this thread? To me they don't seem like they would help anyone, considering all you are doing is post some code that is a complete alternative to the original posters code. And even if it did help him, did you consider that this thread was started more than 3 years ago?

chrjs 42 Junior Poster in Training

When broken down, a char is just a single byte, that is the reason why it only takes char* pointers, because char is a just a byte. You can just cast your double* to a char* pointer and change the size argument so that it accounts for the size of a double. Like this:

//this will write a single double in binary format
outfile.write( (char*)(&a_double), sizeof(double) );

This isn't converting from binary to ASCII, or anything of the sort, it is just treating the 8-byte (on most computers) double as 8 characters (bytes).

chrjs 42 Junior Poster in Training

The variables IP and Address are not strings, like they should be, they are integers. You should make them cstrings or std::strings. Also, on lines 22 and 28, you are just calling the system() function with "ping IP" and "ping Address", it does not actually replace "Address" and "IP" with the value that the user inputed.

I would recommend that you make IP and Address std::strings and that you get the input with the getline command like this:

#include <iostream>
#include <string>
using namespace std;

int main()
{
	string IP;
	
	cout << "Please enter the IP" << endl;
	getline(cin, IP);
}

This means that you will have to call the std::string member c_str() to pass the string you got from the input into the system() function.

chrjs 42 Junior Poster in Training

The first example you gave does not actual write anything in binary, ios_base::binary does not actually change how the data is written to the file. It is just an indicator that you are going to put binary data into the file, but outfile << 1234 << " " << 5678 << " " << 9012 << endl; will still produce the output 1234 5678 9012 (although they might have some '.0's after them cause they are doubles), not those numbers binary representations.

All your second example does is copy data in one file into another, in which case the file being a binary file or a text file would not matter.

chrjs 42 Junior Poster in Training

I am doing this assignment for my computer science course, and I have to write a function that determines if 'x' can fit into an n-bit, two's complement integer.

I am not allowed to use any control statements or operators other than the ! ~ & ^ | + << >> operators. I am also not allowed to use any macros or function calls. I am also not allowed to use any form of casting or any variables that are not of type int, including arrays, structs and unions.

This is assuming a 32-bit, two's complement integers.

This is the code I have written so far. I doesn't really work well, and I can't find what I am doing wrong, any help would be appreciated.

/*
This function is supposed to check if an integer with the 
value of 'x' would fit inside an integer with a 'n' bits

Returns non-zero is 'x' fits in a integer with 'n' bits
Returns zero if it doesn't
*/
int fitsBits(int x, int n)
{
	//declare variables
	int sv, tx;

	//this calculates the 32 - (n + 1)
	//this is the value to shift 'x' to calculate 'tx'
	sv = 32 + (~n);
	
	//shift 'x' left sv bits and assigns it to 'tx', 
	//this is later shifted back the same amount
	//this is done so that 'tx' will equal
	//a version of 'x' that is truncated to fit in 'n' bits
	tx = x << sv;
	
	//make sure leftmost …
chrjs 42 Junior Poster in Training

The reason you were got a segmentation fault is because when you declared char *string[len]; in your first code as opposed to char string[len]; like in your second code, there was no memory bing pointed to by string. The first is a pointer to an array of strings, while the second is just a string.

chrjs 42 Junior Poster in Training

Hmm... I didn't know ANSI C was changed from C90 to C99, I guess I am more than 10 years behind the times...

chrjs 42 Junior Poster in Training

Boston - Foreplay/Long Time

chrjs 42 Junior Poster in Training

"be excellent to each other, and party on dudes"

chrjs 42 Junior Poster in Training

Also people say C/C++ are multiplatform but then any compiler for any language converts the code written by human into machine code i.e "01010101" then why is it that visual basic is not compatible with mac or linux once compiled ?? I just dont understand how C/C++ is so much more "powerful" what sort of powers does it give you ?

machine code can be different from computer to computer, and all libraries are not on every OS, for example, you cannot implement a windows gui on a unix or mac os computer. So something compiled in windows will not necessarily work in mac os, or in a unix-based os

chrjs 42 Junior Poster in Training

Any array is just a pointer to the first element of the array, and when you dereference and element in the array with the brackets like arr[i]; it is the exact same thing as *(arr + i); The amount of elements in the array just means that the pointer is pointing to more data, that is it.

So the array is really a pass-by-value, but all the elements are dereferenced from the same address as that was used to initialize the array in the calling stack frame, so the changes made to the array elements are consistent.

chrjs 42 Junior Poster in Training

you are reading the binary representation of an integer instead of the decimal representation of an integer. result = fread(&num_cust[0], sizeof(int), 1, fp); reads however many bytes the size of an integer is (on most computers, that is 4 bytes.) So assuming a 4 byte integer, the function would read the bytes represented by the characters "3\n27" into the variable result.

You should use the fscanf function for getting input that would be a decimal number like fscanf(fp, "%d", &result);

prgrmmngaccnt commented: thanks for solving the problem. +0
chrjs 42 Junior Poster in Training

you should probably use && instead of || on the 4th line. Also, on the 8th line you should calculate how many minutes to add, instead of just adding 1 (the user could enter 1000 seconds or something like that.) and after that you should change the seconds to fit within 0 <= seconds <= 59

chrjs 42 Junior Poster in Training

I understand it became legal to do so in C99.

Even though it is legal in C99, its not legal in standard C. C code isn't as portable by writing declarations halfway through the code.

chrjs 42 Junior Poster in Training

as I said before, the parameter has to have a type. Thats why the compiler was saying "int assumed", because it didn't know what type the parameter was supposed to be.

void AddBigInt(const BigInt&);
chrjs 42 Junior Poster in Training

In addition to not using code tags, you posted a ridiculous amount of code, no one is going to bother looking through that to find an unspecified problem.

chrjs 42 Junior Poster in Training

If you are asking if there is a program that basically writes all the code for you, the answer is no. There are code-snippets that you can find online or in Flash's AS editor, but there isn't anything that "suggest[s] action script [for] the game in each & every part"

chrjs 42 Junior Poster in Training

I'm sorry, but I can't understand your usage of the English language.

chrjs 42 Junior Poster in Training

at line 42, you can't declare a variable in c in the middle of the program, all variable declarations have to be at the beginning of the code. Also, you can't use a non-constant variable to initialize the size of the array inside brackets. Even if you could do that, you shouldn't have a pointer that points to arrays of characters, you never allocated any memory to that pointer, thats why you are getting the segmentation fault.

chrjs 42 Junior Poster in Training

Indentation is pretty important too, especially when you have a problem with looping

#include<stdio.h>
 
int main()
{
	int pcheck = 1,i;
	int k = 1000
 
	for(i = 2;i < k;i++)
	{
		if((k % i) == 0)
		{
			pcheck = 0; 
			break;
		}
	}	
 
	if(pcheck)
	{
		printf("%d is a prime .\n",k);
	}
	else
	{
		printf("%d is not a prime.\n",k);
	}

	return 0;
}
chrjs 42 Junior Poster in Training

you should get the time before you call cin, then check after cin to see if the user took too much time to enter their answer. probably something like:

clock_t starttime = clock();

cin >> userans;

if ( (clock() - starttime) * CLOCKS_PER_SEC > 20)
{
	//took to long to answer
}
chrjs 42 Junior Poster in Training

Why would you want to use graphics.h anyway? It was written for dos, and almost no one runs dos now.

chrjs 42 Junior Poster in Training

I am not familiar with Qt, but I am guessing that there is some function inherited from GPlainTextEdit that will allow you to access the text in the editor. You need to look up some documentation for a function like that. Also you should put the #endif at the end of the file, not just after the includes.

chrjs 42 Junior Poster in Training

It depends on how the text in the editor is stored, but I am going to assume you are using 1 giant buffer. In that case, you would loop through the characters and every time you hit a newline character you would check to see if you reached the line requested by the user, or if there is no more characters in the buffer.

chrjs 42 Junior Poster in Training

You should build a 8.5 bit computer, it would run faster. And I like how you replied to a thread that was started by you, more than a year ago.

chrjs 42 Junior Poster in Training

Oh, your right Fbody. It looked to me like it was prototyped outside the class because there wasn't any indentation before it, sorry.

chrjs 42 Junior Poster in Training

vivek.kumar: your code is good, but you forgot the void before the function definition and you forgot the '\0' for split2. And I would add a parameter for the delimiter that you use to split the strings.

void split(char *original, char * split1, char * split2, char delim)
{
  int i = 0;
  int j = 0;
  int flag = 0;
 
  while (original[i] != '\0')
  {
     if (flag == 0)
     {
        if (original[i] == delim)
        {
           flag = 1;
           split1[i] = '\0';
        }
        else
        {
           split1[i] = original[i];
        }
     }
     else
     {
        split2[j++] = original[i];
     }
     i++;
  }
  
  if (flag == 0) split1[i] = '\0';
  split2[j] = '\0';
}
chrjs 42 Junior Poster in Training

A linked list is a series of objects that are linked together because each object points to the next.

//a basic structure for a linked list
typedef struct linkedList
{
	int data;
	linkedList* next; //points to the next linkedList struct
} linkedList;

I found this online: http://cslibrary.stanford.edu/103/
I didn't really take a good look at it, but it looks reliable.

chrjs 42 Junior Poster in Training

The prototype for addBigInt is illegal, the parameter has to have a type. Also, shouldn't you be passing in two BigInt classes if you want to add them, and return one two.

Something like:

BigInt addBigInt(const BigInt& bi1, const BigInt& bi2);
chrjs 42 Junior Poster in Training

I am not exactly sure what you are asking, but I think you should try using recursion to call the function for all the surrounding cells.

chrjs 42 Junior Poster in Training

I don't know much about libQGLViewer, but you could try keeping viewer local and just making a variable that points to viewer global, and call updateGL using that pointer.

chrjs 42 Junior Poster in Training

If you want to check if the user's input is valid, you can just put a do-while loop around the code that gets the input from the user.

chrjs 42 Junior Poster in Training

There 3 primary elements of creating a game.

1. Design - Normally pretty straightforward, but you should put good amount of effort into the design of the game before doing anything else.

2. Media - Essentially creating all the 2d images and 3d models and so-forth that you will need in your game. Creating 2d media is normally considered a lot easier than creating 3d media, so for working on your own I would suggest just tackling 2d media.

3. Programming - Writing the code for your game. I don't know what experience you have with GUIs/Graphics Engines in C++, but it will be necessary to implement something along those lines in your C++ code. I would suggest staying away from implementing anything that is platform-specific. Also, you shouldn't use anything too outdated or deprecated (like graphics.h)

chrjs 42 Junior Poster in Training

in C, the keyword const doesn't exist, but it does in C++.

#define is used often in C to declare a name for a value that doesn't ever change throughout the execution of the program. This makes it easier to change values that are used over and over again.

chrjs 42 Junior Poster in Training

This is the function with the warning, to my understanding

char *num2Pstring( number )
	int 	number;
{
	int place = 0;
	int hundreds, tens, units;
	char string[5];

	string [ place++ ] = 'P';
	hundreds = number / 100;
	number = number - ( hundreds * 100 );
	tens = number / 10;
	number = number - ( tens * 10 );
	units = number;

	if ( hundreds != 0 )
		string[ place++ ] = hundreds + 48;
	if ( ! ( ( hundreds == 0 ) && ( tens == 0 ) ) )
		string[ place++ ] = tens + 48;
	string[ place++ ] = units + 48;  
	string [ place ] = 0; 
	return( string );
}

At line 6 you should declare string as a char* and allocate memory the array using malloc(/*bytes to allocate*/) to remove the warning message

chrjs 42 Junior Poster in Training

The if statement and do-while statements are mixed up.
Basically, you wrote

do {
	if (/*expression*/)
	{
		/* some code */
	} while ( /*expression*/ );
}
chrjs 42 Junior Poster in Training

the %4d is saying that the string that this represents cannot exceed 4 characters, while %d would be as many characters as necessary.

r = (unsigned long) a;
int gb = (int) ( r / ONEGB );

r -= gb * ONEGB;
int mb = (int) ( r / ONEMB );

r -= mb * ONEMB;
int kb = (int) ( r / ONEKB );

r -= kb * ONEKB;
int b = (int) ( r );

This part is determining the size of something in a gigabytes, megabytes, kilobytes, bytes format when the size is given simply in bytes (the variable a). It is not finding any addresses.

It divides the total bytes by the number of bytes in a gigabyte to find the number of gigabytes (the result of the division is rounded when casted to an int). Then subtracts the number of bytes represented by however many gigabytes it found to get the remainder of the division and uses that to calculate the amount of kilobytes and so on.

chrjs 42 Junior Poster in Training

Usually when the object is completely black it means that either the file does not have any normals/diffuse data, or your program doesn't have any lighting.

chrjs 42 Junior Poster in Training

I you can't use a switch statement on strings, you have to use an if and else ifs

void ListBoxFrame::OnButton3Click(wxCommandEvent& event)
{
	wxString s;
	
	for (int i = 0; i < ListBox1.IsSelected.Count; i++)
	{
		s = ListBox1.IsSelected[i].ToString();

		if (s == "Foobar")
			wxLogMessage(_T("Listbox item foobar selected"));

		else if (s == "Bazquirk")
			wxLogMessage(_T("Listbox item Bazquirk selected"));

		else if (s == "Widgets")
			wxLogMessage(_T("Listbox item Widgets selected"));

		else if (s == "Gadgets")
			wxLogMessage(_T("Listbox item Gadgets selected"));
	}
}