I know that header guards avoid (most) trouble; call me @n@l if you like, but I just don't like a sloppy header-file tree.
If I draw on paper a box for each header file and connect them by lines representing #include, I like to see a neat hierarchy. But what I usually see is a complex web.
Maybe I am @n@l, but to me that tangled ...
My tools are Linux, gcc and pthreads. When my program calls new/delete from several threads, and when there is contention for the heap, 'arena's are created (see the following link for reference http://www.bozemanpass.com/info/linux/malloc/Linux_Heap_Contention.html). My program runs 24x7, and arenas are still occasionally being created ...
For example, given a str of "Stackoverflow is for every one" and remove of "aeiou",
the function should transform str to "Stckvrflw s fr vry n".
I have one char array of string: str[] and one char array of chars to be removed:remove[]
My Solution: Loop str[] looking for each in character in remove[]. Shift str[] one place left every-t...
I wanted to know how to flush the socket streams while doing socket programming in C. I tried all the options- setting TCP_NODELAY using the following code-
setsockopt(sockfd, IPPROTO_TCP, TCP_NODELAY, (char *) &flag, sizeof(int));
Note: all the flag and sockfd are declared correctly.
I used this function both before send() an...
Given two sorted linked lists, L1 and L2, a solution to compute their
intersection L1 intersection L2.
...
The program saves a settings file as text which contains floating point numbers of type long double. The settings file can only be saved via the GUI (GTK2), while files can also be loaded via the command line and without bringing up the GUI.
Unfortunately, a user reports that in the files he has saved, due to his locale setting, the num...
I'm trying to test if standard library (kernel32.dll) have one of the function.
Code snippet for test:
extern void CreateProcessA (void);
int
main (void)
{
CreateProcessA ();
return 0;
}
The code compiles and links as follow:
cl /c test.c
link test.obj kernel32.lib
This code can be compiled well with Visual C++, but cannot lin...
Hi,
I'm looking for a way to get the uncompressed stream size of an LZMA2 / .xz file compressed with the xz utility.
I'm using liblzma from Windows/Linux for this task, so I guess I'm looking for some C/C++ API in liblzma that will do the trick.
...
Is it possible to have a class inheriting from a struct?
More specifically, how can I wrap a C struct with a class, so that I can pass class pointers to methods that requires struct ptr and cast back when I receive the pointer in e.g. callbacks?
(Or even more specifically, the address of the class should be same same address as the str...
Suppose I have an array of size 10 characters (memset to 0), which I am passing to strncat as destination, and in source I am passing a string which is say 20 characters in length (null terminated), now should I pass the 'count' as 10 or 9?
The doubt is, does strncpy considers the 'count' as size of destination buffer or does it just co...
For example, given string "abc fghi bc kl abcd lkm abcdefg", the function should return string "abcd" and the count of 2.
A O(n^2) solution seems easy but I am looking for a better solution.
Edited: If nothing better than O(n^2) is possible than which approach would be best performance wise.
...
Hi
I've made a program that create 5 pipes and fork 5 processes in a loop. I've managed to send data from the parent to each child processe, when each child processe is overlapped by another program. Each loop is done in the following manner
(parent.c):
// Child process - reads from pipe
if (childpid == 0) {
dup2(fd[0], 0); // re...
The realloc reference says:
The function may move the memory block
to a new location, in which case the
new location is returned.
Does it mean that if I do this:
void foo() {
void* ptr = malloc( 1024 );
unsigned char* cptr = ( unsigned char* )ptr+256;
ptr = realloc( ptr, 4096 );
}
then cptr may bec...
Hello Everyone!
I have an assignment for school that is really got the best of me.
Here is the question:
(2) Write a C program using while
loop(s) in combination with only the
following three output statements
(Each one appearing ONLY ONCE in your
program): printf("* "); printf("\n");
printf(“^“); to print the pattern:
...
Just a quick question
printf("%d", 99 || 44) prints "1" in C
print 99 || 44 prints "99" in perl
There are two different kinds of evaluation. Does each one have a name?
edit: i'm interested to know how this Perl evaluation is commonly called when compared to C. When you say "C example is X, and perl example is not X, but Y" which w...
The reason why it should be empty is because I need to write it in C:
http://stackoverflow.com/questions/951516/what-good-ides-are-availble-for-c/951582#951582
But how to write a dll from scratch?
...
Is there a way to know whether the element in a string in C has a value or not? I have tried using NULL, '', and ' ', but they don't seem to be working. I need to shift the characters down to index 0 without using stdlib functions.
#include <stdio.h>
int main()
{
char literal[100];
//literal[99] = '\0'
literal[98] = 'O';
...
Hello all,
I'm looking for a sample code for IP packet reassembly in C with libpcap*. Is IP packet defragmentation implemented in libpcap library officially? I've found this proposal : http://www.mail-archive.com/[email protected]/msg02991.html[this][1] .
Are there any implementation of defragmentation of IP packets.
...
Hi,
In an Xcode project I have a C file with functions, it compiles and works OK
I want to wrap my C code in struct(s), how will I be able to call them in Objective-C?
...
What is the size of character in C and C++ ? As far as I know the size of char is 1 byte in both C and C++.
In C :
#include <stdio.h>
int main(){
printf("Size of char : %d\n",sizeof(char));
return 0;
}
In C++ :
#include <iostream>
int main(){
std::cout<<"Size of char : "<<sizeof(char)<<"\n";
return 0;
}
No surprises, bot...