c

C: Passing a function pointer in a function it is passed to

I'm trying to write a mapping function that takes a function pointer, and passes it to another function, but gcc is yelling at me. Here is an idea of what I'm trying to do. void map(T thing, void apply(int a, int b, void *cl), void *cl); void function(T thing, void apply(int a, int b, void *cl), void * cl) { for(int i = 0; i < 10;...

How can I reset an array of strings in C language?

Guys, I have a loop that populates "char array_of_strings[100][100];" At some point I want to be able to clean it from all the strings added so far and start adding from position 0. How can I clean/rest it in C? Thanks ...

Can I declare a function that can take pointer to itself as an argument?

Reading a question in stackoverflow, I wondered whether it's possible to declare a function that takes a pointer to itself. I.e. to make such declaration of foo, for which the following would be correct: foo(foo); The simpliest idea is casting to another function pointer (can't cast to void*, since it may be smaller), so the function...

How to remove all spaces and tabs from a given string in C language?

What C function, if any, removes all preceding spaces and tabs from a string? Thanks. ...

implementing ack over UDP?

We have a system (built in C) in place that performs communication over UDP. Recently we have found a necessity to guarantee delivery of packets. My question is: what would be the minimum additions to a UDP based system to ensure delivery using ack packets? Also, ideally without having to manipulate the packet headers. We have applic...

How to parse a value from an XML tag in C language?

I'm getting this string as an input "<operator value=1/>". How in C can I parse out this string to get the "1" back? ...

Calculate minutes until specific time? (C)

What's the simplest way to calculate the number of minutes until 9pm (being today or tomorrow)? Was looking over mktime() but seemed a hassle to get the day # and month, dealing with all that. ...

function call with actual code...

what I'm trying to do is take this function call... assign_sum_to_pixel(&current_pixel, sum); and replace it with the actual code that it calls which is this... /* * assign_ sum_ to_ pixel - Computes averaged pixel value in current_pixel */ static void assign_ sum_ to_ pixel (pixel *current_ pixel, pixel_ sum sum) { curr...

Dissection based learning for C++

Which are the best dissection based learning books for C++? I found that Ira Pohl's C++ by Dissection is good. Are there any other good ones like these. Thanks ...

Parse a char from an xml in C language?

Hi, I'm passing as input to my program: "<param value=s/>" I use this code: char character[1]; sscanf(data, "<param value=%c/>", &character); printf("%c", character); However the output seems to be "s/>" instead of only "s" char. what's wrong here? ...

#defined bitflags and enums - peaceful coexistence in "c"

I have just discovered the joy of bitflags. I have several questions related to "best-practices" regarding the use of bitflags in C. I learned everything from various examples I found on the web but still have questions. In order to save space, I am using a single 32bit integer field in a struct (A->flag) to represent several different ...

How to remove \n or \t from a given string in C?

How can I strip a string with all \n and \t in C? ...

Fuse Filesystem Problem

Hi, i'm developing a fuse filesystem that stores data in the RAM, but i'm having problems when i write something to a file. The file turns into a blank file. Here's the code: #define FUSE_USE_VERSION 26 #include <fuse/fuse.h> #include <string.h> #include <errno.h> #include <stdio.h> #include <stdlib.h> char hello_data[200] = {'h', 'e...

Segmentation fault doubt

I have observed that sometimes in C programs, if we have a printf in code anywhere before a segmentation fault, it does not print. Why is it so? ...

c function call

I'm trying to take this code ... char mysmooth1_ descr[] = "my smooth1: My smooth1 replaced avg() func. and assign sum to pixel"; void mysmooth1 (int dim, pixel *src, pixel *dst) { int i, j; int ii, jj; pixel_ sum sum; pixel current_ pixel; for (i = 0; i < dim; i++) for (j = 0; j < dim; j++) { initialize_pix...

How to capture Control+D signal?

I want to capture the Control+D signal in my program and write a signal handler for it. How can I do that? I am working on C and using a linux system. ...

Extracting bit from a char in C - Interview question

I had a interview today where they asked me to write two "C" functions, one to to extract a single bit and other to extract a range of bits from a character. I took a while and came up with these methods. int extractBit(char byte, int pos) { assert( (pos >= 0) && (pos < 8) ); return ( ( byte & (1<<pos) ) >> pos); } char extractB...

Registry - How to rename key in registry using C++ ?

How to rename key in registry using C++? I want rename key "Myapp\Version1" to "Myapp\Version2". I don't see any function in MSDN about renaming keys in registry. ...

Debug statements for a 4x4 matrix

I'm printing debug statements for a 4x4 matrix. Does anyone know of a better way to do this, without using cout? // num decimal places to show void print( int decimals ) { char fmtString[ 300 ] ; // I'm thinking this should be able to get smaller. sprintf(fmtString, "%%.%df %%.%df %%.%df %%.%df\n" "%...

wrapper printf function that filters according to user preferences

My program writes to a log and to stdout. Every message, however, has a certain priority and the user specifies in Preferences which priorities go to which stream (log or stdout). unsigned short PRIO_HIGH = 0x0001; unsigned short PRIO_NORMAL = 0x0002; unsigned short PRIO_LOW = 0x0003; The preferences is handled by some flags: unsign...