380 Posted Topics

Member Avatar for Zssffssz
Member Avatar for tom12
0
198
Member Avatar for prasenjit_das

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 …

Member Avatar for jmichae3
0
235
Member Avatar for cameronchuck
Member Avatar for torrm

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 …

Member Avatar for Labdabeta
0
428
Member Avatar for vlaskiz

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.

Member Avatar for vlaskiz
0
612
Member Avatar for Labdabeta

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]

Member Avatar for rubberman
0
151
Member Avatar for mrmodest34

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]

Member Avatar for mrmodest34
0
235
Member Avatar for Labdabeta

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 …

Member Avatar for Ancient Dragon
0
179
Member Avatar for Labdabeta

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 …

Member Avatar for Labdabeta
0
294
Member Avatar for Dewey1040

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 …

Member Avatar for L7Sqr
0
147
Member Avatar for Labdabeta

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 …

Member Avatar for gerard4143
0
1K
Member Avatar for mrnutty

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 …

Member Avatar for mrnutty
0
267
Member Avatar for Labdabeta

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)

Member Avatar for Labdabeta
0
224
Member Avatar for Labdabeta

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 …

Member Avatar for Labdabeta
0
1K
Member Avatar for triumphost

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.

Member Avatar for mrnutty
0
234
Member Avatar for droneerror

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 …

Member Avatar for frogboy77
0
3K
Member Avatar for vic s

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 …

Member Avatar for Labdabeta
0
153
Member Avatar for Labdabeta

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 …

Member Avatar for Labdabeta
0
200
Member Avatar for HardToHandle

The problem is on line 19 when you output an endl (newline) after the forward slash. Remove the endl and it should work fine.

Member Avatar for HardToHandle
0
521
Member Avatar for Labdabeta

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> …

Member Avatar for Labdabeta
0
313
Member Avatar for Labdabeta

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. …

Member Avatar for Labdabeta
0
255
Member Avatar for triumphost

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.

Member Avatar for Labdabeta
0
96
Member Avatar for hamby

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.

Member Avatar for hamby
0
7K
Member Avatar for Karlwakim

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.

Member Avatar for Narue
0
112
Member Avatar for Labdabeta

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 …

0
111
Member Avatar for Labdabeta

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: …

Member Avatar for Labdabeta
0
147
Member Avatar for senergy

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 …

Member Avatar for Labdabeta
0
276
Member Avatar for sodha125

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 …

Member Avatar for Labdabeta
0
129
Member Avatar for Labdabeta

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 …

Member Avatar for Labdabeta
0
170
Member Avatar for Labdabeta

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 …

Member Avatar for Fest3er
0
376
Member Avatar for Labdabeta

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 …

Member Avatar for Labdabeta
0
155
Member Avatar for Labdabeta

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 …

Member Avatar for mike_2000_17
0
240
Member Avatar for Labdabeta

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)

Member Avatar for mrnutty
0
301
Member Avatar for Triarius

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 …

Member Avatar for Labdabeta
0
227
Member Avatar for Labdabeta

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 …

Member Avatar for stbuchok
0
56
Member Avatar for Labdabeta

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?

Member Avatar for Labdabeta
0
2K
Member Avatar for Labdabeta

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]

Member Avatar for thines01
0
114
Member Avatar for Labdabeta

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 …

Member Avatar for pritaeas
0
159
Member Avatar for Labdabeta

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?

Member Avatar for JamesCherrill
0
159
Member Avatar for jackly94

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 …

Member Avatar for jackly94
0
212
Member Avatar for maynardjk13

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.

Member Avatar for PrimePackster
0
217
Member Avatar for maria536
Member Avatar for nchy13

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 …

Member Avatar for Labdabeta
0
107
Member Avatar for Labdabeta

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 …

Member Avatar for Labdabeta
0
119
Member Avatar for C++newbie chick

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.

Member Avatar for raptr_dflo
0
250
Member Avatar for Labdabeta

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 …

Member Avatar for Labdabeta
0
116
Member Avatar for imgregduh

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.

Member Avatar for raptr_dflo
0
224
Member Avatar for itzcarol

int types are integers, that means they can only store whole numbers. You need the float type, which stores floating point numbers.

Member Avatar for Labdabeta
0
4K
Member Avatar for Labdabeta

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 …

0
134
Member Avatar for Zssffssz

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. …

Member Avatar for Labdabeta
0
145

The End.