c

multiple fork() question

I have a parent with 5 child processes. I'm wanting to send a random variable to each child process. Each child will square the variable and send it back to the parent and the parent will sum them all together. Is this even possible? I can't figure it out... edit: this process would use shared memory. ...

What operation turns floating point numbers into a "group" ?

Might anyone be famiiar with tricks and techniques to coerce the set of valid floating point numbers to be a group under a multiplication based operation? That is, given any two floating point numbers ("double a,b"), what sequence of operations, including multiply, will turn this into another valid floating point number? (A valid floa...

mprotect API on tiger!

I'm trying to use mprotect API on MacOSX 10.4 (tiger), I tried every possible way i know , it always returns -1, with errno 13, which means "permission denied" while I'm trying to add the write permission to some executable code. The same code exactly works on MacOS X 10.5 (leopard). the code is pretty simple int ret = mprotect((void*...

Execute and Capture one program from another

In win32 programming in C: Whats the best way to execute a win32 console program within another win32 program, and have the program that started the execution capture the output? At the moment I made the program redirect output to a file, but I am sure I must be able to open some sort of pipe? ...

Critiquing my function to skip k chars from input stream.

Working on (what should be) a simple project, taking the input from stdin and reformatting it to match the output specs. I'm just wanting to see what the experts here think of the following function that is supposed to skip k chars up to the end of the line, unless k < 0, where it will keep skipping chars until it reaches newline. 1 #...

Assigning to const int *

void main() { const int * a; *a = 5; } gcc error : assignment of read only location. so, how to assign to *a, without using another variable? and what could be a use of a declaration like above? ...

How can I use _stprintf in my programs, with and without UNICODE support?

Microsoft's <tchar.h> defines _stprintf as 'swprintf' if _UNICODE is defined, and 'sprintf' if not. But these functions take different arguments! In swprintf, the second argument is the buffer size, but sprintf doesn't have this. Did somebody goof? If so, this is a big one. How can I use _stprintf in my programs, and have them work with...

Is fprintf thread-safe?

Is fprintf thread-safe? The glibc manual seems to say it is, but my application, which writes to a file using single call to fprintf() seems to be intermingling partial writes from different processes. edit: To clarify, the program in question is a lighttpd plugin, and the server is running with multiple worker threads. Looking at the...

Networking Framework for C++ (UDP or TCP)?

I'm writing a threaded cross-platform application (Linux/Windows) using SDL and OpenGL, and to do networking I was considering SDL Net2 because it sits on top of SDL_Net. However, I've never done networking in C/C++ before, so I'm unfamiliar with any available cross-platform technologies. Is there anyone with experience with SDL_Net or ...

Where can I find a simple graphics C library for writing directly onto a frame?

I need a simple graphics C library to use on a device where I will be writing directly to the frame. The frame is located in regular memory. There is no graphics acceleration hardware. Nothing fancy. I just want to be able to draw lines, circles, OSD stuff like strings as well. It would be nice to have functions that use good, lean a...

Why does strcmp() return 0 when its inputs are equal?

When I make a call to the C string compare function like this: strcmp("time","time") It returns 0, which implies that the strings are not equal. Can anyone tell me why C implementations seem to do this? I would think it would return a non-zero value if equal. I am curious to the reasons I am seeing this behavior. ...

mmaping two consecutive pages

I'm writing a unit test for my UTF8 manipulation library, and I want my test to segfault if a function goes into a buffer overflow. So I came up with the idea to mmap two pages next to each other in memory, the first with PROT_READ | PROT_WRITE, and the second with PROT_NONE. That way, if any overflow occurs, a segfault is guaranteed. ...

What is the smallest size of bytes that you can store a timestamp?

I want to create my own time stamp data structure in C. DAY ( 0 - 31 ), HOUR ( 0 - 23 ), MINUTE ( 0 - 59 ) What is the smallest data structure possible? ...

Using the open() system call

Hi guys, I'm writing a program that writes output to a file. If this file doesn't exist, I want to create it. Currently, I'm using the following flags when calling open: O_WRONLY | O_CREATE However, when this creates the file, it doesn't give me any permissions to write to it... How can I use open so that it creates a file if it doesn...

File pointer behaviour ?

This is with reference to the question I asked earlier - What is the correct way to declare and use a FILE * pointer in C/C++? MyFile.h char sMsg[712] = ""; #define STD_MSG(string) \ fprintf (stderr, string) #define ERR_MSG(fp, string) \ fprintf (fp, "%s\n", string);\ fflush (fp) MyFile.C #include "PdmTestClnt.h" //---...

How to compile simple C file using GNU C Compiler/gcc & Mobile-Terminal on the iPhone?!

How to compile simple C file using GNU C Compiler/gcc & Mobile-Terminal on the iPhone?! Do I need extra files? ...

Where exactly do function pointers point?

Given that all the primitive data types and objects have memory allocated, it is intuitively easy to imagine the pointers to these types. But where exactly do function pointers point to? Given that instructions are converted into machine code and reside in memory, should we consider they point to the memory location corresponding to the...

What are the benefits of a relative path such as "../include/header.h" for a header?

I've reviewed questions How to use include directive correctly and C++ #include semantics and neither addresses this - nor do the others suggested by SO when I typed the title... What, if any, are the benefits of writing: #include "../include/someheader.h" #include "../otherdir/another.h" compared with using just a plain file name: ...

How to convert between timezones with win32 API?

I have date strings such as 2009-02-28 15:40:05 AEDST and want to convert it into SYSTEMTIME structure. So far I have: SYSTEMTIME st; FILETIME ft; SecureZeroMemory(&st, sizeof(st)); sscanf_s(contents, "%u-%u-%u %u:%u:%u", &st.wYear, &st.wMonth, &st.wDay, &st.wHour, &st.wMinute, &st.wSecond); // Timezone correctio...

GCC / C how to hide console window?

**C newbie alert** How do I compile a C app so that it runs without showing a console window on Windows? I'm using Windows XP and GCC 3.4.5 (mingw-vista special r3). I've googled this exhaustively and I've come up with the following which, according to what I've read, sounds like it's supposed to do the trick, but doesn't on my system:...