c

How do i represent bit info in C?

Hey guys I need to store a value between 0-15 in C , 4 bits are enough for this. How can I just have a variable of 4 bits? Space is a constraint here ...

Strange C construction encountered in academic paper

The code states: void (* log_msg)(char *msg) =printf; void change_and_log(int *buffer, int offset, int value){ buffer[offset] = value; log_msg("changed"); } I'm most concerned with the first part: Firstly, what does the signature void (* log_msg)(char *msg) mean? Is this code simply mapping the function log_msg to print...

bit pattern matching and replacing

Hi, I come across a very tricky problem with bit manipulation. As far as I know, the smallest variable size to hold a value is one byte of 8 bits. The bit operations available in C/C++ apply to an entire unit of bytes. Imagine that I have a map to replace a binary pattern 100100 (6 bits) with a signal 10000 (5 bits). If the 1st byte o...

when do we use function pointers

I am trying to understand the existing code. When do we actually go for function pointers? specially like the one below. struct xx { char *a; (*func)(char *a, void *b); void *b; } struct xx ppp[] = { }; then check sizeof(ppp)/sizeof(*ppp); when do we go with such kind of approach? ...

What kind of type conversions are explicitly redundant according to the standard?

I'm confused about the rules concerning this matter [a good URL might save time in answering]. I notice that a lot of the time conversion implicitly works but other times it's required. e.g. I had expected it to work: long long a; int b; [..] a = b * 1000; but it turns out, 'a' overflows and it's required to a = (long long) b * 1000...

Extracting all the words starting with a particular letter from wordnet

how can extract all the words that start with a particular letter from wordnet. Example if i type A the wordnet should return all the words that start with letter A. ...

change visibility of symbols in shared library files

Hi all, I tried to compile sigintr.c in DD-WRT/src/router/rflow with arm-linux-gcc. The problem I encountered is: sigintr.o: In function siginterrupt': sigintr.c:(.text+0x88): undefined reference to_sigintr' collect2: ld returned 1 exit status make[1]: * [rflow] Error 1 I can find '_sigintr' in libc.so, but unfortunately...

Compiling PHP 5.3.3 From Source Into Apache.

Just compiled 5.3.3 from source (win32). Trying to test some header() stuff but it looks like it won't work with CLI sapi. Any good docs on putting your compiled source into apache as a module, just like i'd normally do with the pre-compiled module. Basically my test would be from CLI php -r "header('Content-Type: text/plain', true, 4...

Purpose of static keyword in array parameter of function

While browsing some source code I came across a function like this: void someFunction(char someArray[static 100]) { // do something cool here } With some experimentation it appears other qualifiers may appear there too: void someFunction(char someArray[const]) { // do something cool here } It appears that qualifiers are onl...

How to convert a stream of bytes to another encoding?

I'm trying to convert a stream of bytes with MultiByteToWideChar() WinAPI fucntion. Documentation says function fails with ERROR_NO_UNICODE_TRANSLATION on incomplete strings (no trailing byte in multibute encoded string). How do I prevent this error? The only way that comes to mind is not to convert the last multibyte character of input...

Subtracting two numbers without using '-' operator

hi, i tried with the following code , but i can't understand why it's giving me wrong answer. i am computing the 2's complement and adding with another no. #include <stdio.h> int add(int a, int b) { while (a) { a = (a & b) << 1; b = a^b; } return b; } int sub(int a, int b) // add a with b's 2's complement. ...

Shortest way to print "Success"

I have been trying this problem SUCCESS at spoj but I am not able to get optimal solution to that problem I tried int main(){return !puts("Success");} but it takes 45 characters. Any alternate suggestions to solve the problem? People have solved it using 24 characters also. ...

Simple C string manipulation

Hi all, I trying to do some very basic string processing in C (e.g. given a filename, chop off the file extension, manipulate filename and then add back on the extension)- I'm rather rusty on C and am getting segmentation faults. char* fname; char* fname_base; char* outdir; char* new_fname; ..... fname = argv[1]; outdir = argv[2]; fna...

Linking in several C object files that contain functions with equivalent signature

Lets say I have a C++ program and I want to call functions from a C object file in it. The constraint is that I'm not allowed to make any changes to the C source files. In this case I would include the C header as extern "C" in my C++ file, call the function, compile the C object using gcc -c, and pass the result to g++ along with the a...

Structure initializing problem in C

I'm writing a program for a "Set" data structure in C. It's working fine when one instance of Set is present, but it doesn't work when two instances of Set are present. Also my code for removing an element is not working when the candidate is the first element. Can someone help me? Here is the code: Set.h Set.c Test.c ...

How to read this C Array declaration/intialization?

char *names[] = { [3] = "foo", [1] = "bar", [0] = "man"}; int i; for (i=0; i<sizeof(names)/sizeof(char); i++) { puts(names[i]); } What are the function of the brackets in the above declaration? Also, why does the resulting loop iterate 3 times instead of 4 and produce this output: man bar ...

Would a novice learning C and Scheme simultaneously be considered bad practice?

I've been on and off with the C language for the past year(?) until two months prior to present day when I decided to take my learning a bit more seriously. In some areas of the language I feel comfortable, but I know that by anyone's terms I'm still considered an amateur and have much, much more to learn. Recently, I've heard nothing b...

C: enum VS #define for mathematical constants?

I'm wondering what would be the best way to store math constants that are used throughout an entire program? #define PI 3.14159265 #define SPEEDOFLIGHT 2.99792458e8 or enum constants { PI = 3.14159265; SPEEDOFLIGHT = 2.99792458e8; } Thanks ...

WDK : get processId by name.exe

Hi, I'm developing a driver in Windows Filtering Platform and I need the process ID of another process to do what I need to do. I know only the file name of that process (name.exe). In win32 I could use the function CreateToolhelp32Snapshot to get the list of all processes and I could search the PID there. ( http://msdn.microsoft.com/en...

Boolean array using "char"

Hi, I made an object that actually represents an array of 8 booleans stored in a char. I made it to learn something more about bitwise operators and about creating your own objects in C. So I've got two questions: Can I be certain if the below code always works? Is this a good implementation to make an object that can't get lost in C, ...