c

Floating point calculation change depending on the compiler

When I run the exact same code performing the exact same floating point calculation (using doubles) compiled on Windows and Solaris, I get slightly different results. I am aware that the results are not exact due to rounding errors. However I would have expected the rounding errors to be platform-independent, thereby giving be the same ...

C Programming linux , read system inputs like ping or ls -l

hello. i trying make a custom method what causes return a char with system output. the pseudocode like this. char *my_Out(char *in ){ in = system ("ping %s",in); return in; } thanks for the help. ...

Help finding c api.

Im coding a simple c/gtk+ app connected to a mysql database. The gui and db code is done, now I need to make some reports based on database data, I thought the easier way to do this is by using an api that would let me output the data to a Excel or openoffice spreadsheet,PDF would be helpful too. The problem is dont find any. ...

load wave file data into a buffer

Hello, gcc 4.4.2 c89 I have a wave file: 8000 Hz 16 bit I am wondering if there anyway I can load the raw data of this wave file into a buffer. Many thanks for any advice ...

A `union` doubt

Suppose I define a union like this: #include <stdio.h> int main() { union u { int i; float f; }; union u tst; tst.f = 23.45; printf("%d\n", tst.i); return 0; } Can somebody tell me what the memory where tst is stored will look like? I am trying to understand the output 1102813594 that this p...

How to print out the memory contents of a variable in C?

Suppose I do a double d = 234.5; I want to see the memory contents of d [the whole 8 bytes] How do I do that? ...

C++/C/Java: Anagrams - from original string to target;

Hi there, I'm trying to solve this problem : http://uva.onlinejudge.org/external/7/732.html. For the given example, they give us the original word, for example TRIT and the target "anagramed" string, TIRT. Objective: We have to output all the valid sequences of 'i' and 'o' (push and pop's, respectively) which produce the target string ...

How to use pcap_breakloop?

Hi all, I have a pcap_loop function in another function, that captures packets until the user stops it, i.e. void functionA() { signal(SIGINT, terminate_process); pcap_loop(handle, -1, callback, NULL); ... } void terminate_process(int signum) { pcap_breakloop(handle); pcap_close(handle); } Is it possible to set a d...

Format float number

Hi I want to format float numbers such that it will be displayed as follows: decimal.fraction where decimal = max 11 digits and fraction = max 9 digits and if no fraction part it should display not fraction and for more than 11 digits in decimal part representation will be in scientific form. Can anyone help me ? ...

Disabling multi core programmaticaly

Is there any possible way of disabling multi core functionality on windows and just using a single core using C\C++? Any library that allows it? My application access one of our chip modules used to communicate with the host. We suspect someone else is accessing this module and changes it. The strange thing is that it only happens on a m...

How does this program work?

#include <stdio.h> int main() { float a = 1234.5f; printf("%d\n", a); return 0; } It displays a 0!! How is that possible? What is the reasoning? I have deliberately put a %d in the printf statement to study the behaviour of printf. ...

strtok() and empty fields

I am serializing some C structure to string and than deserializing it with strtok(). But, unfortunately, strtok() don't detect empty fields (eg 1:2::4). Is there any alternative function? ...

Tracking the death of a child process

Hi! How could I track down the death of a child process without making the parent process wait until the child process got killed? I am trying a client-server scenario where the server accepts the connection from a client and forks a new process for each and every connection it accepts. I am ignoring SIGCHLD signals to prevent zombie...

Embedded C++, any tips to avoid a local thats only used to return a value on the stack?

I have a local that's only used for the purposes of checking the result from another function and passing it on if it meets certain criteria. Most of the time, that criteria will never be met. Is there any way I can avoid this "extra" local? I only have about 1MB of storage for my binary, and I have several thousand function calls that...

Why does this code not output the expected output ?

This can be a good question for finding bugs. No? Okay for beginners at least. #define SIZE 4 int main(void){ int chars_read = 1; char buffer[SIZE + 1] = {0}; setvbuf(stdin, (char *)NULL, _IOFBF, sizeof(buffer)-1); while(chars_read){ chars_read = fread(buffer, sizeof('1'), SIZE, stdin); printf("%d, %s\n", chars_read,...

How do I link a static library in a cpp source file?

There's a #pragma command to link in a library from the source file rather than from the project settings. I just can't seem to remember it. Can anyone here remind me? Thanks ...

OpenCV grouping white pixels

Hi Guys, I've done the hard work, turning my iSight camera on my MacBook into an infared camera, converted it, set the threshold etc.. and now have an image that looks something like this: My problem is now; I need to know how many blobs are on my image by grouping the white pixels. I don't want to use cvBlob/cvBlobsLib, I'd rather ju...

GStreamer, how to add a delay to one of the input streams?

I created a GStreamer pipeline that takes multiple input sources: camera audio/video, a logo and a screen capture video that is received as a RTP stream). It combines these sources into one video using the videomixer element. The screen capture stream however seems to lag 2 seconds behind the rest. In order to fix this I would like to i...

C: strtok on pointer inside a struct

Hi, I have struct with this definition: typedef struct gRow{ char *txt; char *fileName; int line; } gRow; and i want to use strtok on the txt string. so, in some function that has gRow *row, i do this: strtok(row->txt, SEPERATOR_CHARACTERS); and this is the point where i get Segmentation Fault. if i replace it with: st...

Using Macros to Define Constants for CUDA

I'm trying to reduce the number of instructions and constant memory reads for a CUDA kernel. As a result, I have realised that I can pull out the tile sizes from constant memory and turn them into macros. How do I define macros that evaluate to constants during preprocessing so that I can simply adjust three values and reduce the number...