c

Concatenate all arguments (except the executable name)

Is there a C function that can concatenate all the passed arguments (except the name of the executable) into a char* and return it? ...

Computational cost

Is there someone that knows what is the computational cost for this two piece of code? while(n>2) n = sqrt(n); while(n>2) n = log(n) ...

How are circular #includes resolved?

In c lets say we have 2 files 1.h #include<2.h> blah blah and we have 2.h #include<1.h> code How is this resolved?? ...

Returning char* / Visual Studio debugger weirdness

We're getting some funny behavior in the Visual Studio debugger with the following. I'm not sure if it's the code or some debugger weirdness (seen stuff like it before). We are trying to return a pointer to an value in an array. The weird behavior is that the value of x changes to equal y after func() is called a second time...at least,...

Sending binary data over IPC from C to Python

Hi All I have a C program and a Python program on the same machine. The C program generates some data in nested structures. What form of IPC is the best way to get this data across to the python program? Serializing in C (especially nested structures) is a real bear, from what I hear, due to lack of serialization libraries. I am not...

Returning local data from functions in C and C++ via pointer

I have argument with my friend. He says that I can return a pointer to local data from a function. This is not what I have learned but I can't find a counterargument for him to prove my knowledge. Here is illustrated case: char *name() { char n[10] = "bodacydo!"; return n; } And it's used as: int main() { char *n = name(...

Compile EXPAT to statically-linked .a on Windows

I am writing C program on Windows with MingW and want to use EXPAT XML library. I want to compile my program statically, so I need static .a library. Is there any way to compile EXPAT to .a static, independent library on Windows? ...

global variable for getenv() ?

Which is the global variable which holds all the environmental variables for getenv() ? In what glibc file is this var filled with env vars ? I believe it to be **environ but when I set an env var in bash it only ouputs the SSH_AGENT_PID env var. Why is SSH_AGENT_PID set and why is it the only one that is set ? DOCUMENT_ROOT='/foopath...

Tips to write thread-safe UNIX code?

What are the guidelines to write thread-safe UNIX code in C and C++? I know only a few: Don't use globals Don't use static local storage What others are there? ...

What happens if during a signal handling in UNIX, the same signal gets sent to the program?

Any ideas on this? Is there some kind of a signal queue, or does it get dropped? While we are at this question, is it true that signal handlers should do as minimal work as possible? I read somewhere that a signal handler should use a pipe and just write one byte to it, indicating what the program should do. Then somewhere else the pro...

Except OOP, what is making C++ better than C

Well that may sound like a troll question, but since C++ seems hard to fully master (and I never really knew STL was actually "part" of it), I wanted to know what are the disadvantages to use C instead of C++ when not relying much on OOP. C++ can have a very much sophisticated syntax sometimes, which is kinda confusing me while trying t...

pointers and string parsing in c

I was wondering if somebody could explain me how pointers and string parsing works. I know that I can do something like the following in a loop but I still don't follow very well how it works. for (a = str; * a; a++) ... For instance, I'm trying to get the last integer from the string. if I have a string as const char *str = "some...

address of array ptr equal to to it's value ?

Possible Duplicate: C: How come an arrays address is equal to its value? SA In C I tried to print the address of the pointer of an array. int a[3] = {0,1,2}; printf("\n%p",a); printf("\n%p",(&a)); the 2 statement prints the same value why?thanks in advance ...

linux sockets: server exits before client

Hello, I have this prog, just a skeleton for a simple sever and client connection. I will make it a chat. (dont mind the thread func and signals..) server: #include <stdio.h> #include <stdlib.h> #include <unistd.h> #include <errno.h> #include <time.h> #include <string.h> #include <signal.h> #include <sys/types.h> #include <sys/socket....

Glib: Can I reuse a pointer queued to be freed with g_test_queue_free?

Using Glib Testing framework, I would like to know if I can reuse a pointer queued to be freed with g_test_queue_free? Here's a code sample of what I'm trying to do: static void some_test() { gchar* tmp; tmp = func_returning_gchar_ptr (...params...); g_assert(tmp); g_test_queue_free(tmp); tmp = func_returning_gchar_ptr (......

Optimized version of strstr (search has constant length)

My C program had a lot of strstr function calls. The standard library strstr is already fast but in my case the search string has always length of 5 characters. I replaced it with a special version to gain some speed: int strstr5(const char *cs, const char *ct) { while (cs[4]) { if (cs[0] == ct[0] cs++; } ...

New to programming, don't get 2D/3D arrays

Hey everyone, I'm basically new to programming. I've decided to try and get started with C (not C++ or C#) and so far I've been doing pretty well. I managed to get far as two-dimensional arrays before I started to falter. While I think I broadly understand 2D integer arrays, I certainly don't understand 3D string arrays. I'm learning by...

How do I convert a decimal integer into a single hexadecimal character? (C)

Hi, I am trying to convert a decimal integer into hexadecimal. I've done a lot of searching online, and have found many ways to do this. However, every way I found converts to a string; for example, I can convert 100 into "64". That isn't what I need to do. I want to be able to convert 100 into '0x64', which is an entirely different mat...

Subclass another application's control?

Is it possible to subclass another application's control so that my application could do something before the other application executes it's code and receiving the lParam and wParam? Ex: subclassing notepad's Edit control and when the user types, being able to know what the user typed? would SetWindowSubclass work if I provide the hWnd ...

Is there a library repository for C?

Possible Duplicate: Why there is not a comprehensive c archive network? Everyone knows that C is very small language, it has just language primitives and almost no standard library (no data structures or algorithms). Therefore I have a question, how do I find good C libraries for data structures, algorithms and perhaps system...