c

types of buffers

Hello guys, Recently an interviewer asked me about the types of buffers. What types of buffers are there ? Actually this question came up when I said I will be writing all the system calls to a log file to monitor the system. He said it will be slow to write each and every call to a file. How to prevent it. I said I will use a buffer an...

What is the fastest substring search algorithm?

OK, so I don't sound like an idiot I'm going to state the problem/requirements more explicitly: Needle (pattern) and haystack (text to search) are both C-style null-terminated strings. No length information is provided; if needed, it must be computed. Function should return a pointer to the first match, or NULL if no match is found. Fa...

Python and C coupling

Hi, I tried loading C shared library .so in Python using ctypes.CDLL class (Linux). Here is the link to which tells what I did. As I see the documentation it says CDLL class assumes that function returns int types. I've a doubt here what if I need to return variable of type other than the int type from a function in C?. And to what exte...

Position of intersection of a 3d vector and a cube

I am having a total mind blank on this at the moment. I have a cube (voxel) that is defined by a centre point and a width, height and depth of 1. If I have a vector with an origin from the centre of the box (E.g. (-0.7,-0.7, -0.7)) how do I calculate the point at which the vector intersects the outside of the box? EDIT: The box is alwa...

How can I use Git's malloc wrapper in my code?

I want to use the git's malloc and realloc wrappers in my code for OOM(out of memory) conditions. Here is its code: void *xmalloc(size_t size) { void *ret = malloc(size); if (!ret && !size) ret = malloc(1); if (!ret) { release_pack_memory(size, -1); ret = malloc(size); ...

BSD Licensed Big Integer C lib with fast modpow

I'm searching a fast (specially the p^n mod g operation, should be implemented with montgomery) big integer library. I know there is GMP but GMP is LGPL which doesn't fit my requirements. I tried http://www.acme.com/software/bigint/ and tried to optimize the modpow in there. But do to the fact that the data is stored with base 2^32 it i...

extract every audio-channel in a quicktime file

I want to extract every audio channel in a quicktime movie with the QuickTime-API. That means if the file has 5.1 surround, i want 6 audio files in the end. But at the moment I don't know how to manage that. Until now I have: OSStatus err = noErr; MovieAudioExtractionRef extractionSessionRef = nil; Boolean allChannelsDiscrete = true; in...

Regarding C++ class access/manipulation in C.

Hello. I've been reading questions on Stack Overflow for a few weeks now... this'll be my first question. So recently I've looked into making C access/manipulate a C++ class. I understand that ideally one shouldn't compile components in C and C++ separately under normal circumstances, but this isn't an option at the moment. I looked in...

How to convert c code to matlab

I have a c code about 1200 lines long and i want to convert it into matlab. is there any software or website where i can do it. ...

Is the primary implementation of *any* popular programming language interpreter written in C++?

At the moment I am considering whether or not to rewrite a programming language interpreter that I maintain in C++. The interpreter is currently implemented in C. But I was wondering, is the primary implementationbecause, certainly, people have made versions of many interpreters using a language other than the one used by the original a...

DllMain calls from C# thread creation/deletion seem to be unbalanced?

I'm using a library (ANet) which is written natively in C and I am interfacing with it using C# via a small subset wrapper dll which i've made in C and statically links to it. The library (ANet) has a DllMain which simply tracks the number of references to it (so "Process attach" and "Thread attach" counts) but it seems to go into the ne...

convert number to slash divided hex path

Hey, I need to generate a path string from a number (in C) e.g: 53431453 -> 0003/2F4/C9D what I have so far is this: char *id_to_path(long long int id, char *d) { char t[MAX_PATH_LEN]; sprintf(t, "%010llX", id); memcpy(d, t, 4); memcpy(d+5, t+4, 3); memcpy(d+9, t+7, 4); d[4] = d[8] = '/'; return ...

In C, what does a colon mean inside a declaration?

Possible Duplicate: What does unsigned temp:3 means I'm learning some kernel code, and came along the following line (in linux 2.4, sched.h, struct mm_struct): unsigned dumpable:1; What does this mean? ...

How to implement a static graph in C

Hello, I need to store a graph for the map of a game inside a game server written in C. The graph has ~200 nodes and 3 kinds of edges that can connect two nodes (these three kind can also overlap: a node can be connected by 2 edges of two different types for example). The maximum degree of a node is something like 5-6 nodes. What I wou...

having memcpy problem

char *a=NULL; char *s=NULL; a=(char *)calloc(1,(sizeof(char))); s=(char *)calloc(1,(sizeof(char))); a="DATA"; memcpy(s,a,(strlen(a))); printf("%s",s); Can you plz tell me why its printing DATA½½½½½½½½■ε■????How to print only DATA?? Thanks ...

Reallocate a 2d char array

I have following code int wordLenght = 256, arrayLength = 2, i = 0, counter = 0; char **stringArray = NULL; stringArray = calloc(arrayLength, sizeof(*stringArray)); for(counter; counter<wordLenght; counter++) stringArray[counter] = calloc(wordLenght, sizeof(stringArray)); while(1) { printf("Input: "); fgets(stringAr...

structure program giving unexpected output

/* It is not entering data into the third scanf() statement .*/ #include<stdio.h> #include<conio.h> #include<string.h> void main(void) { struct book { char name; int pages; float price; }; struct book a1,a2,a3,a4; printf("Enter data into 3 books\n"); scanf("%c %d %f",&a1.name,&a1.pages,&a...

Copying between byte array and unsigned long

What's the best/recommended way to copy data between a byte array and an integer in C? Currently I'm using memcpy, which doesn't feel right to me. A sample of the sort of thing I'm doing is below. struct alpha { unsigned char byte_array[20]; } void function(struct alpha *st) { unsigned long num; /* Do some stuf...

C-equivalent of the 'setw' function

In c++, setw function is used to set the number of characters to be used as the field width for the next insertion operation. Is there any function in C, I mean, in standard c library, which does the same thing? ...

mergesort array of int using pointers

Hello everyone! For school I have to program a merge sort using only pointers. I've tried almost everything, but I can not get it working. #include <stdio.h> #include <stdlib.h> #include <string.h> #define num_elementi(array) (sizeof(array)/sizeof(array[0])) void selsort(int arr[],int n); void swap(int * a, int * b); void print(int a...