380 Posted Topics
Re: I am not sure I understand. Why can't you just do this: [CODE]cout<<"<"<<"$"<<endl;[/CODE] | |
Re: Do not ask for code. Suggestions are fine. I would suggest using a 256-base system and store the digits in an std::string. Make this into a class with all the normal arithmetic operators defined. Next add a function called factorial (or maybe overload the ! operator?) and write the traditional … ![]() | |
Re: This code looks fine to me. If you wrap it into classes it could be even better, then you could probably add functionality for fitting the objects into the container (since usually not every square meter of the container is filled). I would suggest a containerItem class and a container … | |
Re: I am not entirely certain, but maybe the problem has to do with the unusual characters? You may need to store them in an int and not a char to allow for long unicodes. It may be easier if you translate the code into english. | |
Is this a viable BIGENDIAN test: [CODE]int tmpvaluethatwillneverreallybeused=1; bool bigendian=(*(char*)(&tmpvaluethatwillneverreallybeused)==1); void myFunction() { if (bigendian) { //do big endian specific code } else { //do little-endian specific code } }[/CODE] | |
Re: Try running this code and see what you can make of it: [CODE]void recursiveTest(int cntr) { if (cntr==0) { cout<<"Pivotting..."<<endl; } else { cout<<"Winding up..."<<endl; recursiveTest(cntr-1); } cout<<"Unwinding..."<<endl; } int main() { recursiveTest(5); return 0; }[/CODE] | |
I have some code in C++ that uses an std::vector of std::strings to store an array of strings. I need to convert it into C. I thought that I would just create c versions of the functions I need (vector.back,vector.push_back,string.operator+=) but am getting lost in the double pointers. Can anybody … | |
I was wondering if there is any way using the mingw g++ compiler to make code that acts like this: [CODE]#define myLanguageBlock(X) doMyLanguageBlock(#X) void doMyLanguageBlock(const char* code){/*this executes the code as if it were in another language, I have already written this function*/} int main() { myLanguageBlock( this is all … | |
Re: I see two ways of doing this. Either read the entire contents of the file into a string and then break the string apart, or use file seeking functionality. Here is an example of the file seeking functionality for n=3 strings: [CODE]FILE *file=fopen(filename,"r"); if (!file)return; char buffer[4];//this will store our … | |
How do I do assembly code with the mingw-g++ compiler. All the websites I checked say that this should work: [CODE]int add(int a, int b) { int c=0; asm("mov %[aVal],%eax;add %[bVal],%eax;mov %eax,%[cVal]" : [cVal] "=i" (c) : [bVal] "i" (b) : [aVal] "i" (a)); return c; }[/CODE] But instead I … | |
Re: I am working on this because it looks like fun. I am just wondering what the challenge is, implementation wise. I have a BoggleBoard class now, and a function in it called getAllMoves() this function takes an array of c-style strings and an integer array length. Should I return an … | |
I was just wondering how exit worked? Does it use some lower-level language feature in its implementation? Is it compiler-specific? What is it? (I am talking about the function in stdlib.h btw) | |
I have an alpha beta interface and have implemented a tic tac toe class from it. For some reason my AI tends to occasionally make stupid moves (such as making a fork rather than blocking a 2 in a row) I was wondering if anybody can see where I went … | |
Re: As I understood it 0 is the same as '\0' and NULL is defined as (void*)0. As an ASCII character though '\0' is used to terrminate a string. | |
Re: You would need a boolean value to store the state of the primality of the number. A simpler approach is to use a function, which hopefully you have learned. This is what I usually use for a primality check: [CODE]bool isPrime(int x)//checks if x is a prime number { for … | |
Re: If it is that urgent, this can be done quickly and easily using the dreaded global variable. Not to recommend extensive use of globals but just this once they could make for an easy solution: [CODE]int f1,f2; void functionOne(/*functionOne arguments*/) { f1++;//increment f1 //code for function One } void functionTwo(/*functionTwo … | |
I was working on a project when I thought that maybe a ::. operator would look funny in some code. Just for fun I typed that into the global scope area like this: [CODE]::. int main() { //etc...[/CODE] and my code completion software said too many results to display. My … | |
Re: The problem is on line 19 when you output an endl (newline) after the forward slash. Remove the endl and it should work fine. | |
I have this code for AlphaBeta implementation and have created versions of the required interfaces that work perfectly (I have debugged them quite thoroughly). Unfortunately my algorithm keeps returning an empty vector and score of 0. Here is the code: [CODE]#include <vector> #include <limits.h> using namespace std; typedef vector<unsigned char> … | |
How can I get the coordinates of the output of a truetype font. I need to write a function like so: [CODE]struct CartesianCoord{float x,float y}; CartesionCoord *printfont(const char *filename,char ch, int &len) { /*Read the font in filename.ttf and convert it to a set of vertices describing the resulting shape. … | |
Re: From what I understand of your problem, which in my opinion is poorly worded, a possible solution may be to rotate the points one degree at a time and then use some kind of detection algorithm. I fear that perhaps a learning AI may be necessary. | |
Re: It probably said that std::vector<string> has no function push_back(int) because on line 6 you say v.push_back(1), but v is a string vector, not an int vector. | |
Re: hit the 'x' just under the scroll bar for the source code viewing area. You can also find this 'x' by looking at the message you got and moving to the top-right of its box. I do not suggest getting rid of this necessarily as it is relatively important information. | |
I have a difficult function to write and I have no idea where to begin. Here is the definition of what I need to write: "A function f(x,y) which returns true if the binary number formed by concatenating the bits of x, 8*y-1 zeroes and a one is prime, false … | |
I have a function that takes a reference to an interface class as a parameter. I have created a derived class from the interface class, but when I try to call the function with an instance of my derived class as an argument I get a compiler error saying "error: … | |
Re: My suggestion (although I do not have much experience in Windows API programming per se) would be to create a pop-up window and force it to remain on top of the z-order at all times and visible at all times. That way any attempt of the user to interact with … | |
Re: Try filling out this code with whatever corresponding functions exist in your library: [CODE]const char up=0;//put the value for up here const char down=0;//put the value for down here const char right=0;//put the value for right here const char left=0;//put the value for left here const char exit=0;//put the value … | |
I have been teaching myself algorithms and I am stuck with the AlphaBeta AI algorithm. I want to test my knowledge of it with a TicTacToe simulation. The thing is I want it to be easy to modify for any two player game and I cannot figure out how to … | |
I need to know where to find a tutorial on javascript assuming javascript is what I need. I want to make a dynamic website with buttons that can toggle visibility of text. Really I just need something like a link that makes a bunch of text appear then disappear but … | |
A friend asked me how to write and use a DLL in C++. I told him that I had to check and make sure my understanding was accurate. So here I am. Would this work as a DLL: myDLL.cpp: [CODE]#include "myDLL.h" void DLL_EXPORT ConstructMyInt(myIntStruct &i){i.val=0;} void DLL_EXPORT DoSomething(myIntStruct &i){i.val*=i.mul++;} BOOL … | |
I am getting extra garbage at the end of the string returned by this function. Why? [CODE]char *read(char *fname) { FILE *file=fopen(fname,"r"); printf("Opening input file...\n"); if (file==NULL) return NULL; int length=0; char *ret=new char[length]; while (!feof(file)) { char ch=fgetc(file); char *temp=new char[length+1]; for (int i=0; i<length; i++) temp[i]=ret[i]; delete[]ret; if … | |
I am really confused as to the purpose of the unary + operator. What in the world does it do? I have tested it and it doesn't return the absolute value. Does it just return the operand? And if so what purpose is it?! (I mainly care about integer types) | |
Re: I would absolutely suggest using classes. Something like this will do nicely: [CODE]class enemyCar { private: char car[4][3]=//put your cars' code here int x; int y; public: enemyCar(/*any constructor parameters you may want*/);//this is the constructor void step();//executes one turn for this car void draw();//draw the car in the correct … | |
I have a website where I show a lot of C++ source code in tables by creating styles named, preprocessor, operator, keyword, etcetera and applying these styles where appropriate to highlight the syntax in my code. The problem is that I have so far been doing it manually. For example … ![]() | |
I have a project that I have formatted for Doxygen. I use extra header files to hold extra classes. The thing is that Doxygen only generates documentation for the first header file. How do I get it to document all of the files I specify? | |
I need to clear the output console buffer from within java on a windows console. I was thinking of a batch call to "cls" how can this be achieved? [CODE]public static void cls(){ //clear the screen pretty please! }[/CODE] | |
How do you show code on a website? Right now I define a bunch of CSS styles called Comment, Preprocessor, Keyword, etcetera. Then make a two column table, make the left column line numbers and and the right column each row has a line of code. Then I manually go … | |
I accidentally hit Source->Externalize Strings... on eclipse and now hundreds of string literals are stored in a properties file. I want them back scattered about my code. How can I do this without re-entering them? | |
Re: I cannot see the problem, but then again it is hard to read your code because you seem to have ignored modulation. In case you do not know, modulation is the practice of chunking your code together into separate functions so that they are easier to read. For example you … | |
Re: The problem is that you are sending ARRAY_SIZE to you sum and average functions. The issue is that the array may not be filled up all the way to ARRAY_SIZE. You need to pass numElements to those functions instead. | |
Re: I could be wrong but I do not think that you can access two dimensional arrays using pointer dereferencing like you are trying to do. Regardless I think it would be better to use a "fake" two-dimensional array like this: [CODE]int &access2DArray(int *array, int width, int height, int x, int … | |
I need to convert a true type font into a list of three dimensional vertices using openGL. I looked at the NeHe tutorial, but it only creates a display list from the font and as far as I can tell it is not possible for me to extract the vertices … | |
Re: From what I can see it does not appear as if you have allocated any extra space in your array, so at line 48 when you access stdRec[last+1] you are indexing an array out of bounds. | |
I need to know how to extract the data in a display list in opengl. I have a font and use it to create a display list to draw, but then I want to get the actual vertexes of it so I can use them for collision checking. How can … | |
Re: I suggest you dont use global variables, as they tend to be messy and you tend to run into problems like this one. Instead make your Reader/Writer functions take an ofstream variable and use it. | |
Re: int types are integers, that means they can only store whole numbers. You need the float type, which stores floating point numbers. | |
I type using the Dvorak simplified keyboard, but I have a programming competition in a few weeks during which I have to use their keyboards, or I can plug in my own. The problem is that my keyboard is a soft-wired Dvorak keyboard (ie: The keys say dvorak letters but … | |
Re: Null is defined as 0. Whenever you use null you could also use 0 although null is used more for pointers since the pointer value of 0 is reserved. Void is a data type with absolutely no space. It is used as a pointer to be a generic data type. … |
The End.