c

Windows Mobile/C: Wait until variable changes

I'm currently writing a wrapper library for windows mobile in C/C++. I have to implement and export the following functions: void start_scanning(); int wait_for_scanning_result(); void stop_scanning(); start_scanning() is called to start the scanning process. wait_for_scanning_result() will wait until a result is available and return ...

Invalid Value for size_t

What do people use to denote that size_t is invalid? -1 does not work, and 0 can be a valid size. Thank you ...

Can/Why using char * instead of const char * in return type cause crashes?

I read somewhere that if you want a C/C++ function to return a character array (as opposed to std::string), you must return const char* rather than char*. Doing the latter may cause the program to crash. Would anybody be able to explain whether this is true or not? If it is true, why is returning a char* from a function so dangerous? Th...

How can I use PCRE to get all match groups?

Hi, I am inexperienced with using C, and I need to use PCRE to get matches. Here is a sample of my source code: int test2() { const char *error; int erroffset; pcre *re; int rc; int i; int ovector[OVECCOUNT]; char *regex = "From:([^@]+)@([^\r]+)"; ...

How do I represent a Unicode character in a literal string ISO/ANSI C when the character set is ASCII?

In Perl, I can say my $s = "r\x{e9}sum\x{e9}"; to assign "résumé" to $s. I want to do something similar in C. Specifically, I want to say sometype_that_can_hold_utf8 c = get_utf8_char(); if (c < '\x{e9}') { /* do something */ } ...

Including source files in C

So I get the point of headers vs source files. What I don't get is how the compiler knows to compile all the source files. Example: example.h #ifndef EXAMPLE_H #define EXAMPLE_H int example(int argument); // prototype #endif example.c #include "example.h" int example(int argument) { return argument + 1; // implementation ...

Problem starting a process with CreateProcess()

The question is given like this: Using the CreateProcess () in the Win32 API. In this instance, you will need to specify a separate program to be invoked from CreateProcess(). It is this separate program that will run as a child process outputting the Fibonacci sequence. Perform necessary error checking to ensure that a non-negative ...

How do you set system time using C/C++?

I have an embedded system (ARM 9263) running an RTOS, IAR tools. The system supports the standard time() function which gives me the current time. I need the reverse call, that is I need to set the time - is there a "C" standard way to do this? I've googled around, sure thought it would be obvious, but perhaps it is platform dependent? I...

Is there any way to synchronize parent and child in C using one pipe in Unix?

Suppose both parent and child use one pipe for writing and reading means when one writes then only other read otherwise it blocks. Is there any way to do it? I tried to do it with sleep function but due to race conditions, it does not give the correct output. This is my code #include <stdio.h> #include <stdlib.h> #include <string.h> #i...

How an uninitialised variable gets a garbage value?

Possible duplicate Uninitialized values being initialized? When we create a variable and don't initialize it, then some (random) number called garbage value is assigned to it. How this value is assigned to the variable? What is whole concept/mechanism behind this? Does this happen only in C? ...

How to read a float from binary file in C?

Everything I'm finding via google is garbage... Note that I want the answer in C, however if you supplement your answer with a C++ solution as well then you get bonus points! I just want to be able to read some floats into an array from a binary file EDIT: Yes I know about Endian-ness... and no I don't care how it was stored. ...

Erlang: is there an equivalent to the C preprocessor ## directive?

Is there an equivalent to the C preprocessor directive ## in Erlang? Let's say I want to concatenate two atom() using a -define preprocessor directive, how would I do this without having run-time side-effects? ...

fileno, F_LOCK and F_ULOCK become undeclared and unavailable when I add std=c99 flag to gcc

I have these headers in a c code #include <stdio.h> #include <unistd.h> Everything compiled fine until I added -std=c99 flag to gcc command (to enable restrict). And this triggered the following errors. warning: implicit declaration of function fileno error: F_LOCK undeclared (first use in this function) error: (Each u...

Simple struct question

struct { char a; int b; } x; Why would one define a struct like that instead of just declaring it as: struct x { char a; int b; }; Thanks ...

Is there a c/c++ multi-monitor library for changing between XP's desktop setting of dualview or clone?

I am writing an application where it would be helpful to automatically switch between having Windows XP's desktop in dualview or cloned. The application uses a small wxWidgets window for the GUI. It would be nice to have a button within the GUI that could easily switch between dualview and cloned. Is there a c/c++ library that gives...

Active Accessibility (COM) calls return differently depending if caller is a thread vs. a process. What?!

I have code that uses Microsoft Active Accessbility to get information about the active window. Strangely, I can only enumerate all the controls in a window (in this case Internet Explorer) if I use a process. If I spawn a thread and call the EXACT same code, MSAA will return only a subset of controls. Usually just the menu bar and toolb...

Is there a programmatic way to check stack corruption

I am working with a multithreaded embedded application. Each thread is allocated stack sizes based on its functionality. Recently we found that one of the thread corrupted the stack by defining a array of local variables that was more than the stack size. The OS is uItron. My solution, I registered a timer for 10 mS, and this timer will...

Garbage collection vs. non garbage collection programming languages

So if I understand well, Garbage collection automatically deallocates objects that are not used by the program anymore. like the garbage collector in java. I hear in languages like C that don't support garbage collection the programs can have memory leaks and subsequently exhaust the memory. So what are the errors that programmer make ...

Appending data to a null character in character array to send data through socket

Hi Forum, I am a newbie programmer.I have a problem as goes below, void SockSend() { char *sendbuf; int sendsize; /* send data size(variable size)*/ int iPos = 0, iTotSize; char hdr; char *data = "ABCDEFGHIJKLMNO"; /* its just example, data can be any thing */ sendsize = strlen(data); hdr = '\0'; /* header charac...

how to create files named with current time?

I want to create a series of files under "log" directory which every file named based on execution time. And in each of these files, I want to store some log info for my program like the function prototype that acts,etc. Usually I use the hard way of fopen("log/***","a") which is not for this purpose.And I just write a timestamp function...