Find a prime number?
To find whether N is a prime number we only need to look for all numbers less or equal to sqrt(N). Why is that? I am writing a C code so trying to understand a reason behind it. ...
To find whether N is a prime number we only need to look for all numbers less or equal to sqrt(N). Why is that? I am writing a C code so trying to understand a reason behind it. ...
This should be really simple, but it's consumed multi-hours of my time, and I have no clue what's going on. I'm rendering a flat-colored full-screen quad to a texture, then reading back the result with glGetTexImage. It's GPGPU related, so I want the alpha value to behave as if it's any of the other three. I'm using an FBO, texture form...
I'm learning DirectX from a book about game programming, and it uses the following method for a game loop: long int start = GetTickCount(); while(true) GameRun(); void GameRun() { if(GetTickCount() - start >= 30) //do stuff } This makes start equal whatever the time is (I'm guessing get tick count gives the number o...
When I use #include <d3d9.h> in my programs, I no longer need to include windows.h to use windows functions like WinMain, and CreateWindow. Is this because d3d9.h &c. include windows.h? Mainly, I'm wondering if it is possible to substitute windows.h with d3d9.h, etc, and still be able to se any functions I could use with windows.h. ...
I have an issue with my C++ code for college. I can't seem to understand why my sRecSort() method isn't working. Any help? This is really confusing me! #include <iostream> #include <algorithm> #include <string> #include <fstream> #include <sstream> using namespace std; void sRecSort(string n[], int s[], string e[], int len){ for (in...
I'm new to programming. I want to make a card game with C++ / Allegro. The graphics api is irrelevant though. I want it to have many buttons you can click. I'm wondering the proper way this is done. For instance, how does windows know which control you click on from your cursor. I would use an array of rectangles and check each rectangle...
I wish to read from cin in C++ from the current position up until a newline character into a string. The characters to be read may include spaces. My first pass fails because it stops on the first space: string result; cin >> result; If cin is given: (cd /my/dir; doSometing)\n The variable result only gets: (cd I would think ...
A common question that comes up from time to time in the world of C++ programming is compile-time determination of endianness. Usually this is done with barely portable #ifdefs. But does the C++0x constexpr keyword along with template specialization offer us a better solution to this? Would it be legal C++0x to do something like: con...
How can I setup IRQ using C++ and Masm, most of the search results refer me to Nasm, I am trying to create a bootloader of my own, I get it to boot from cd (iso) then I want to add menu options but cant seem to setup IRQ An example that uses nasm can be found at Bran's Kernel Development looking something like global irq0 ; 32: IRQ0 i...
Hey guys, I'm wondering if this is the right approach to writing a thread-safe queue in C++? template <class T> class Queue { public: Queue() {} void Push(T& a) { m_mutex.lock(); m_q.push_back(a); m_mutex.unlock(); } T& Pop() { m_mutex.lock(); T& temp = m_q.pop(); m_mutex.unlock(); return temp; } private...
I declared and initialized an array having [100][1000][1000] char elements(100MB), it didn't say about a stack overflow at the first time.But when I running it after a while it throws a Stack overflow exception! I increased the -Stack Reserve Size- to 200,000,000 in project options->linker->system but it didn't worked! I'm working using ...
Hello, I was trying to write a program for the problem I mentioned above, the numbers (i.e the lists) can be of unequal length, I was not able to figure out a way to do this other than the most commonly thought of approach i.e reverse list-1 reverse list-2 find the sum and store it in a new list represented by list-3 reverse the li...
I have a function like this: MyFunction(double matrix[4][4]) {/*do stuff*/} I am calling this from an outer function (the otuer function is a member function of a class, in case that matters): OuterFunction() { double[4][4] x; initialize(x); //this function puts the data I want in the matrix MyFunction(x); } I am trying to debug th...
I have a program that looks like the following: double[4][4] startMatrix; double[4][4] inverseMatrix; initialize(startMatrix) //this puts the information I want in startMatrix I now want to calculate the inverse of startMatrix and put it into inverseMatrix. I have a library function for this purpose whose prototype is the following: ...
I'm writing a Win32 application using C++. In this application I'm handling the WM_PAINT message: case WM_PAINT: hdc = BeginPaint(hWnd, &ps); GdiplusStartup(&gdiplusToken, &gdiPlusStartup, 0); DrawM(ps.hdc, hWnd); EndPaint(hWnd, &ps); break; And in the DrawM function I'm having something like this: void DrawMap(HDC hdc, HWND hW...
Bitmap bff(L"1.jpg"); bff.Save(L"2.jpg", &Gdiplus::ImageFormatJPEG, NULL); This creates a new file 2.jpg with zero-bytes length. Isn't it supposed to write an image file that is identical to 1.jpg? Why I'm having zero-bytes length files? I'm doing this test because writing other Bitmaps to files end the same way. ...
I am writing a command-line Qt4 script (using QCoreApplication) on Mac OS X. I am using this code adapted from C++ Programming with Qt 4, 2nd ed. p. 313: QTemporaryFile outFile; if (!outFile.open()) return; QString fileName = outFile.fileName(); QTextStream out( out << initial_text; outFile.close(); QProcess::execute(editor, QStr...
I have got two questions. 1 - I get Unicode code-points and how do I get the character associated with this code-point? Something like: int code_point = 0xD24; char* chr = (char*) code_point; But the above code fails by throwing exception. 2 - Suppose the code-point is stored in a file and I read the code-point to a string, how do I...
This isn't cross-platform code... everything is being performed on the same platform (i.e. endianess is the same.. little endian). I have this code: unsigned char array[4] = {'t', 'e', 's', 't'}; unsigned int out = ((array[0]<<24)|(array[1]<<16)|(array[2]<<8)|(array[3])); std::cout << out << std::endl; unsigned char b...
Ok, so I came across this code snippet in my textbook that's supposed to echo every other character a user types in. Now, I understand the every other character part, but I'm having difficulty with the use of cin.get(). I understand why the first cin.get() is there, but why is it also inside the loop? I'm guessing I'm not fully grasping ...