c++

Function equivalent to sprintf() with maximum number of characters to be copied?

function(char* name) { char sql[50]; sprintf(sql, "select %s;", name); } What's the best way to make sure only 50 chars of name are copied to sql in the case name is larger than what sql can hold? (sprintf with a N parameter?) Thank You. ...

pointer and reference question (linked lists)

Hi there, I have the following code struct Node { int accnumber; float balance; Node *next; }; Node *A, *B; int main() { A = NULL; B = NULL; AddNode(A, 123, 99.87); AddNode(B, 789, 52.64); etc… } void AddNode(Node * & listpointer, int a, float b) { // add a new node to the FRONT of the list Node *temp; temp = new ...

Direct access to harddrive?

I was wondering how hard disk access works. Ex, how could I view/modify sectors? Im targeting Windows if that helps. Thanks ...

Is a signal sent with kill to a parent thread guaranteed to be processed before the next statement?

Okay, so if I'm running in a child thread on linux (using pthreads if that matters), and I run the following command kill(getpid(), someSignal); it will send the given signal to the parent of the current thread. My question: Is it guaranteed that the parent will then immediately get the CPU and process the signal (killing the app if ...

O(log n) algorithm to find the element having rank i in union of pre-sorted lists

Given two sorted lists, each containing n real numbers, is there a O(log n) time algorithm to compute the element of rank i (where i coresponds to index in increasing order) in the union of the two lists, assuming the elements of the two lists are distinct? EDIT: @BEN: This i s what I have been doing , but I am still not getting it. ...

Main Function Error C++

I have this main function: #ifndef MAIN_CPP #define MAIN_CPP #include "dsets.h" using namespace std; int main(){ DisjointSets s; s.uptree.addelements(4); for(int i=0; i<s.uptree.size(); i++) cout <<uptree.at(i) << endl; return 0; } #endif And the following class: class DisjointSets { public: void addelements(int x); in...

Need help using libpng to read an image

Here is my function... I don't know why it's not working. The resulting image looks nothing like what the .png looks like. But there's no errors either. bool Bullet::read_png(std::string file_name, int pos) { png_structp png_ptr; png_infop info_ptr; FILE *fp; if ((fp = fopen(file_name.c_str(), "rb")) == NULL) { ...

Sockets and multithreading

Hi to all! I have an interesting (to me) problem... There are two threads, one for capturing data from std input and sending it through socket to server, and another one which receives data from blocking socket. So, when there's no reply from server, recv() call waits indefenitely, right? But instead of blocking only its calling thread, ...

How do you perform macro expansion within #ifdef?

Hi all, I have some fairly generic code which uses preprocessor macros to add a certain prefix onto other macros. This is a much simplified example of what happens: #define MY_VAR(x) prefix_##x "prefix_" is actually defined elsewhere, so it will be different each time the file is included. It works well, but now I have some code I ...

What code have you written with #pragma you found useful?

I've never understood the need of #pragma once when #ifndef #define #endif always works. I've seen the usage of #pragma comment to link with other files, but setting up the compiler settings was easier with an IDE. What are some other usages of #pragma that is useful, but not widely known? Edit: I'm not just after a list of #pragma d...

Tool for analyzing memory leaks in a COM object

Hi, If there is a tool for analyzing memory leaks in a c++ COM Object, please provide a link here If no such tool exist, what would be the best way to handle memory leaks ? Thank You ...

How to open a .a file

I've a little problem: I have to open a linker file, that have .a extension. I use Dev-C++, I don't know if it would be useful for you :-P I hope you will answer soon! Oh, and excuse me for my bad English, tell me if I made some mistakes! Thanks!! Ale ...

Performance of Serialized Objects in C++

Hi Everyone, I'm wondering if there is a fast way to dump an STL set to disk and then read it back later. The internal structure of a set is a binary tree, so if I serialize it naively, when I read it back the program will have to go though the process of inserting each element again. I think this is slow even if it is read back in co...

MSBuild: Custom target for header files(Skipping target when included files updated)

Hello, I'm writting custom tool for VS2010. This tool executes GCC-XML compiler to produce xml output for c++ header file. When i change header file with my custom rule, everything is ok. But when i change some file, included in this header: Skipping target "_GCCXML" because all output files are up-to-date with respect to the input fi...

Audio processing in C# or C++

Hi, I would like to create an application that uses AI techniques and allows the user to record a part of a song and then tries to find that song in a database of wav files. I would have liked to use some already existing libraries for the audio processing part. So, could you recommend any libraries in C# which can read a wav file, ge...

Type Declaration - Pointer Asterisk Position

Hello, in C++, the following means "allocate memory for an int pointer": int* number; So, the asterisk is part of the variable type; without it, that would mean something else (that's why I usually don't separate the asterisk from the variable type). Then what is the reason the asterisk is considered something else, instead of being p...

generate random double numbers in c++

how to generate random numbers between two doubles in c++ , these number should look like xxxxx,yyyyy . thanks ...

Unresolved External Symbol linker error (C++)

Hi, I am trying to develop abstract design pattern code for one of my project as below.. But, I am not able to compile the code ..giving some compile errors(like "unresolved external symbol "public: virtual void __thiscall Xsecs::draw_lines(double,double)" (?draw_lines@Xsecs@@UAEXNN@Z)" ).. Can any one please help me out in this... #i...

Handling wm_mousewheel message in WTL

I am trying to handle wm_mousewheel for my application. Code: BEGIN_MSG_MAP(DxWindow) MESSAGE_HANDLER(WM_MOUSEWHEEL, KeyHandler) END_MSG_MAP() . . . LRESULT DxWindow::KeyHandler( UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL &bHandled ) { if(uMsg==wm_mousewheel) { //Perform task. } return 0; } But...

How to implement a FIFO listcontrol in MFC ?

I need to implement a list control using MFC with the number of lines being fixed. It should Use FIFO with the number of lines being a fixed number. Is there an inbuilt option to this? Or a programmable method. ...