From safe, managed code in C#, I would like to call a function in a C API that receives an array of pointers (void**).
I have the corresponding managed array of IntPtr objects, but the Marshal methods advertised in the documentation at MSDN do not seem sufficient to provide an IntPtr to an unmanaged block of memory with the correct cont...
When I compile a simple Hello World! program that uses the sscanf function on my local Debian lenny x64, it works. But when I upload the same program to the server running CentOS x86, it will not work. If I do not use sscanf, then the program works on both computers.
gcc -std=c99 -O2 -pipe -m32
If I compile it with sscanf but without -...
I'm trying to figure out what the pid is of a process that sent the SIGCHLD signal, and I want to do this in a signal handler I created for SIGCHLD. How would I do this? I'm trying:
int pid = waitpid(-1, NULL, WNOHANG);
.. because I want to wait for any child process that is spawned.
Thanks,
Hristo
...
EDIT: I had made a mistake during the debugging session that lead me to ask this question. The differences I was seeing were in fact in printing a double and in parsing a double (strtod). Stephen's answer still covers my question very well even after this rectification, so I think I will leave the question alone in case it is useful to s...
Hey, if I had this code:
printf( "%8.2f" , .23 );
It outputs 0.23. How do I get it to simply output .23?
Thanks.
...
Are there any libraries to parse Textile (Textile to HTML) which will work in an Objective C iPhone app? C libraries will work too.
Update: I couldn't find any sufficiently developed libraries in C/Obj-C, but I did find one written in Javascript, which I used through an invisible UIWebView.
Link: Javascript textile parser
...
If I have two types of strings as:
const char *str1 = "This is a string with \"quotes escaped at the end\"";
const char *str2 = "This is a \"string\" without quotes at the end";
testFn(str1);
testFn(str2);
int testFn(const char *str)
{
// test & return 1 if ends on no quote
// test & return 0 if ends on quote
return;
}
I wo...
I create a linked list dynamically and initialize the first node in main(), and I add to the list every time I spawn a worker process. Before the worker process exits, I print the list. Also, I print the list inside my sigchld signal handler.
in main():
head = NULL;
tail = NULL;
// linked list to keep track of worker process
dll_node_t...
Before anything, I apologize if this question has been asked before.
I am programming a simple packet sniffer for a class project. For a little while, I ran into the issue where the source and destination of a packet appeared to be the same. For example, the source and destination of an Ethernet frame would be the same MAC address all o...
I am fairly new to C. (I have good knowledge of C# [Visual Studio] and Java [Eclipse]) I want to make a program that stores information. My first instinct was to use a database like SQL Server. But I don't think that it is compatible with C. So now I have two options:
Create a struct (also typedef) containing the data types.
Find a way...
Is it possible to get access to an individual member of a struct or class without knowing the names of its member variables?
I would like to do an "offsetof(struct, tyname)" without having the struct name or member variable name hard coded amoungst other things.
thanks.
...
Hello
I have tried to do fork() and piping in main and it works perfectly fine but when I try to implement it in a function for some reason I don't get any output, this is my code:
void cmd(int **pipefd,int count,int type, int last);
int main(int argc, char *argv[]) {
int pipefd[3][2];
int i, total_cmds = 3,count = 0;
int in = 1;...
Hi,
This program I'm doing is about a social network, which means there are users and their profiles. The profiles structure is UserProfile.
Now, there are various possible Graph implementations and I don't think I'm using the best one. I have a Graph structure and inside, there's a pointer to a linked list of type Vertex. Each Vertex ...
how can something print 3 times when it only goes the printing code twice? I'm coding in C and the code is in a SIGCHLD signal handler I created.
void chld_signalHandler() {
int pidadf = (int) getpid();
printf("pidafdfaddf: %d\n", pidadf);
while (1) {
int termChildPID = waitpid(-1, NULL, WNOHANG);
if (termChildPID == 0 || term...
I vaguely remember reading about this a couple of years ago, but I can't find any reference on the net.
Can you give me an example where the NULL macro didn't expand to 0?
Edit for clarity: Today it expands to either ((void *)0), (0), or (0L). However, there were architectures long forgotten where this wasn't true, and NULL expanded to...
Does anyone see a problem with this, its not working saying bad file descriptor not sure why?
pipe(pipefd[0]);
if ((opid = fork()) == 0) {
dup2(pipefd[0][1],1);/*send to output*/
close(pipefd[0][0]);
close(pipefd[0][1]);
execlp("ls","ls","-al",NULL);
}
if((cpid = fork())==0){
dup2(pipefd[0][1],0);/*read from in...
Can anyone help me with the programming code for self similar fractals in computer graphics using c language?
...
I have a simple program to check if a port is open, but I want to shorten the timeout length on the socket connection because the default is far too long. I'm not sure how to do this though. Here's the code:
#include <sys/socket.h>
#include <sys/time.h>
#include <sys/types.h>
#include <arpa/inet.h>
#include <netinet/in.h>
#include <errn...
Hello,
Redhat 5.5
gcc version 4.1.2
I have a directory call lib, and in that directory I have all the shared libraries (about 30) that we get from our customer as we use their API. We link with this API.
directory structure:
/usr/CSAPI/lib
However, our customer will update their API so we get new libraries, normally about 3 or 4.
...
Hello all, I wrote a quick program which executes every statement before giving a seg fault error.
struct foo
{
int cat;
int * dog;
};
void bar (void * arg)
{
printf("o hello bar\n");
struct foo * food = (struct foo *) arg;
printf("cat meows %i\n", food->cat);
printf("dog barks %i\n", *(food->dog));
}
void main(...