Inside the read FD_SET I have several sockets:
the main socket listening for new connections
accepted sockets listening for incoming data.
I set the timeout for 30 seconds and called select(). I quickly noticed the behavior is different for each:
When a new client connects on the listening port, it returns immediately from blocking...
Is there a C strings library for C (not C++) that implements an abstraction over char * and wchar_t * strings?
The requirements are:
to be BSD/MIT/CDDL licenced
implements some kind of reference count mechanism
has support for regular expressions
has Unicode support
Thanks,
...
Suppose you have one array a[]=1,2,4,6 and a second array b[]=3,5,7. The merged result should have all the values, i.e. c[]=1,2,3,4,5,6,7. The merge should be done without using functions from <string.h>.
...
Suppose a process is creating a mutex in shared memory and locking it and dumps core. Now in another process how do i ensure that mutex is already locked but not owned by any process?
...
In K&R ANSI C book, section A.7.4.5 (Unary Minus Operator) it is stated:
... The negative of an unsigned quantity is computed by subtracting the promoted value from the largest value of the promoted type and adding one; ...
How exactly is this calculated? Could you give a short C example? I don't see how this could yield the negati...
I have C header file containing the following type definition:
// example.h
typedef struct Vertex {
int color;
} Vertex;
I try to wrap this struct with SWIG, but apparently I am doing something wrong. My SWIG interface file looks like
// example.i
%module example
%inline %{
#include "example.h"
}
But if I copy the contents of my ...
I am trying to write a custom allocator for debugging purposes (as an exercise) in C, where I will be using a single linked list to hold together the free list of memory using the First Fit Algorithm. I've shown below the structure I would like to create in an "Empty Memory Node".
How do I write the header block (a union to be specific)...
When I convert an unsigned 8-bit int to string then I know the result will always be at most 3 chars (for 255) and for an signed 8-bit int we need 4 chars for e.g. "-128".
Now what I'm actually wondering is the same thing for floating-point values. What is the maximum number of chars required to represent any "double" or "float" value a...
Please note that this is not homework and i did search before starting this new thread. I got http://stackoverflow.com/questions/1522994/store-an-int-in-a-char-array
I was looking for an answer but didn't get any satisfactory answer in the above thread.
Here's my requirement: I want to encode my data(say an integer) in a byte array an...
Is there anything other than DDD that will draw diagrams of my data structures like DDD does that runs on Linux?
ddd is okay and runs, just kind of has an old klunky feeling to it, just wanted to explore alternatives if there are any.
The top part with the grid of this image is what I am talking about:
...
I was wondering if there were any good free graphics libraries for C that are easy to use?
It's for plotting 2d and 3d graphs and then saving to a file. It's on a Linux system and there's no gnuplot on the system right now.
Or would it just be simpler to switch to another language, and if so which one would be easy to learn?
...
My application creates a thread and that runs in the background all the time. I can only terminate the thread manually, not from within the thread callback function.
At the moment I am using TerminateThread() to kill that thread but it's causing it to hang sometimes.
I know there is a way to use events and WaitForSingleObject() to make t...
The Definitive ANTLR Guide starts with a simple recognizer. Using grammar verbatim to target C-runtime fails because '%s' means something to ANTLR:
$ cat T.g
grammar T;
options {
language = C;
}
@parser::includes
{
#include <stdio.h>
}
/** Match things like "call foo;" */
r : 'call' ID ';' {printf("invoke %s\n", $ID.t...
I have to use a legacy C routine in the application I am developing. The code in here works, but I have to convert almost all the fields to char arrays in order to use it. There is a better way to do it? I have tried some version using strings, all to no avail.
This is the code found in the original header file...
typedef struct PXUCAM...
I am doing a cross-platform C (not ++) game with both linux (main) and windows (alternate) binaries.
Until now I used devcpp to compile in windows, but I have trouble getting some libraries to work right, and I heard it is possible to compile a windows binary from withing Linux.
However, I don't know where to get started.
The game uses ...
Consider this code:
char* foo(int myNum) {
char* StrArray[5] = {"TEST","ABC","XYZ","AA","BB"};
return StrArray[4];
}
When I return StrArray[4] to the caller, is this supposed to work?
Since the array is defined on the stack, when the caller gets the pointer, that part of memory has gone out of scope. Or will this code work...
I am using the following code to tokenize the string in C and using " ," to make tokens but i wanted to know when it make token of string when " " came and when "," occur in the string.
char *pch;
pch = strtok(buffer, ", ");
while (pch!=NULL) {
printf("%s\n", pch);
pch = strtok(NULL, " ,");
}
...
Hi, I'm trying to build a project I have and it has several exported functions. The functions follow the stdcall convention and they get mangled if compiled with GCC as
Func@X
Other compilers mangle the name like this:
_Func@X
Is any way I can force GCC to mangle the names of the exported functions to the later example?
...
Hi, I'm just learning C and am using xCode for it (not sure if it matters). This code:
#include <stdio.h>
int main (int argc, const char * argv[]) {
int myInt;
myInt = 2;
myInt *= ( (3*4) / 2 ) - 9;
printf("myInt = %d", myInt);
return myInt;
}
Outputs this:
Session started at 2009-11-09 15:51:15 -0500.]
myInt...
Hi, I'm trying to write a program which needs to create some other processes. I'm used to the Windows API but now I need my program to be able to run in a Linux platform too.
Is it possible to do it in a portable manner? Do I have to use the preprocessor for that purpose?
EDIT: I need to wait for it to finish before continuing to do th...