c

Avoid trailing zeroes in printf()

I keep stumbling on the format specifiers for the printf() family of functions. What I want is to be able to print a double (or float) with a maximum given number of digits after the decimal point. If I use: printf("%1.3f", 359.01335); printf("%1.3f", 359.00999); I get 359.013 359.010 Instead of the desired 359.013 359.01 Can ...

Webcam library for C on Linux?

Is there any c library to get a video from the webcam on linux? ...

How to guarantee files that are decrypted during run time are cleaned up?

Using C or C++, After I decrypt a file to disk- how can I guarantee it is deleted if the application crashes or the system powers off and can't clean it up properly? Using C or C++, on Windows and Linux? ...

C++ string manipulation

My lack of C++ experience, or rather my early learning in garbage collected languages is really stinging me at the moment and I have a problem working with strings in C++. To make it very clear, using std::string or equlivents is not an option - this is char* 's all the way. So: what I need to do is very simple and basically boils down...

Most efficient way to move an image from a C program to Java and shown on the screen?

Background I am capturing video using the video4linux 2 spec. It is captured using a C program in real-time. I also have a Java frontend that can run both locally and remotely. The remote side was easy, I just compress the images to JPEG and ship them over a mini-http server to the client that decompresses them and shows them on the ...

What would cause a ERROR_INTERNET_INCORRECT_HANDLE_TYPE (12018) with InternetQueryOption?

I'm working on a simple little function to download a file from an SSL-enabled website using the WinInet functions, namely InternetOpen and InternetOpenURL. I had was initially failing the call to InternetOpenURL with a ERROR_INTERNET_INVALID_CA (12045) because I was using a self-signed certificate on my test server, and found out (htt...

Using dlsym and adding -ldl to flags

I am trying to write a C program that uses dlysm, and I keep getting an undefined deference to dlysm. I think I need to set my -ldl flags but I have no idea how to do this. I am very new to linux and setting variables. If this is what I need to do can someone help me out with the commands? ...

What is the output of this program, and what does it return to the OS ?

It's kind of a C puzzle. You have to tell if the program finish its execution, if so, how much time it takes to run and what it returns to the OS. static unsigned char buffer[256]; int main(void) { unsigned char *p, *q; q = (p = buffer) + sizeof(buffer); while (q - p) { p = buffer; while (!++*p++); } return...

Making a custom run Dialog with C or C++?

Well i would like to make a custom run dialog within my program so that the user can test commands without opening it themselves. The only problem is, msdn does not provide any coverage on this. If i cannot make my own custom run dialog and send the data to shell32.dll (where the run dialog is stored) i will settle for the code that can ...

C Inline Functions and Memory Use

If I use inline functions, does the memory usage increase? ...

how to control popen stdin, stdout, stderr redirection?

I am confused about how popen() redirects stdin, stdout and stderr of the child process in unix. The man page on popen() is not very clear in this regard. The call FILE *p = popen("/usr/bin/foo", "w"); forks a child process and executes a shell with arguments "-c", "/usr/bin/foo", and redirects stdin of this shell (which is redirected...

CPU Affinity

Is there a progamatic method to set CPU affinity for a process in c/c++ for the linux operating system. ...

Calling a C function with a varargs argument dynamically

I am programming in C against a third party library (in HP/Mercury Loadrunner) that allows a varargs-style variable size argument list for one of it's functions. I want to call this function but I do not know up front how many arguments I will have. There is a function made by one of my predecessors that serves somewhat but the problem...

Do class/struct members always get created in memory in the order they were declared?

This is a question that was sparked by Rob Walker's answer here. Suppose I declare a class/struct like so: struct { char A; int B; char C; int D; }; Is it safe to assume that these members will be declared in exactly that order in memory, or is this a compiler dependent thing? I'm asking because I had always assumed...

MySQL And C applications

When building a application that accesses a MySQL database on linux using C/C++ i have to dynamically link into the mysql client library. Is there a way in which i can statically link the application so that the mysql client libraries are no longer required? What is the best practice, with regards to C\C++ development, to include rathe...

RGB back buffer in Win32

I have an array of RGB values, whose size I can guarantee to match the client area of a window on screen. Using the Win32 API, what are the easiest and fastest ways to get the contents of my array on the screen in response to a WM_PAINT message? If it makes it simpler/faster, we can assume it's a 32-bit display and each element of the ...

How to best sort a portion of a circular buffer?

I have a circular, statically allocated buffer in C, which I'm using as a queue for a depth breadth first search. I'd like have the top N elements in the queue sorted. It would be easy to just use a regular qsort() - except it's a circular buffer, and the top N elements might wrap around. I could, of course, write my own sorting implemen...

Waitpid equivalent with timeout?

Imagine I have a process that starts several child processes. The parent needs to know when a child exits. I can use waitpid, but then if/when the parent needs to exit I have no way of telling the thread that is blocked in waitpid to exit gracefully and join it. It's nice to have things clean up themselves, but it may not be that big of...

Passing data from C to Java

What is the best way to pass data between a C server to a Java applet? Currently it's done by using a buffer and copying bytes to it using memcpy, but if the object ever changes I have to hunt down every instance of where it's being sent to the applet and have it changed. Is there a better way to pass object to java? How would you do it...

How to scan in two arrays from user??

I'm relatively new to programming and I have to write a function that reads in input from the user and to fill two arrays then compare them. I guess what I'm confused on is how to read in both arrays. This is what I'm supposed to do, Write a table_diff fuction that compares two arrays of integers and returns the subscript of the first ...