c

Larger integer to smaller unsigned type conversion in C

I was goint through k & r. I was having problem in understanding following lines on page 197(section A6) Integral conversions: any integer is converted to a given unsigned type by finding the smallest non negative value that is congruent to that integer,modulo one more than the largest value that can be represented in the...

Why must we convert everything to a char* when we write it to a file?

Out of curiosity, why are we converting something to a char* when we write it to a ( binary ) file? ...

character constant:\000 \xhh

Can anyone please explain the usage of the character constant \000 and \xhh ie octal numbers and hexadecimal numbers in a character constant? ...

Keeping variables global to the library scope in C

Is there any way to keep global variables visible only from inside a library while inaccessible from programs that access that library in C? It's not that it is vital to keep the variable protected, but I would rather it if programs couldn't import it as it is nothing of their business. I don't care about solutions involving macros. ...

Adaptation problem with the Blowfish Encryption in C

I'm writing a program that implements the Boneh-Franklin Identity Based Encryption. For the actual encryption methods, I use Blowfish which I got from (https://voltar.org/). I'm trying to adapt the blowfish encryption/decryption code to my program. The difference in my program is that I read the message from the standard input, encrypt i...

How to get the NPP Instance inside a NPAPI C plugin

Hi, I have written a NPAPI plugin in C which needs to call the NPN_Invoke function (in order to call a JavaScript function). But NPN_Invoke() takes the NPP instance as a parameter. Only the NP_New() and NP_Destroy() functions get passed NPP instance. How do I get this NPP instance? Thanks in advance. ...

Most efficient algorithm to generate a site map?

..given an URL as input (C programming language). (Sitemap specifications from sitemap.org). ...

Objective-C sample code for HMAC-SHA1

I need to generate HMAC-SHA1 in Objective C. But i didnt find anything that works. I tried with CommonCrypto, using CCHMAC, but didnt works. I need to generate a hmac and after generate HOTP number. Somebody have any example code in Objective C or C? ...

A Question About Function Pointer In C

There's the following declarations: void qsort(void *lineptr[], int left, int right, int (*comp)(void *, void *)); int numcmp(char *, char *); int strcmp(char *s, char *t); Then, somewhere in the program there is the following call: qsort((void**) lineptr, 0, nlines-1, (int (*)(void*,void*))(numeric ? numcmp : ...

Getting contents of localhost using winsock

Hey! I am trying to connect to my localhost and the index page I have there. But every time I try I just get: Dados -> HTTP/1.1 400 Bad Request Date: Thu, 16 Apr 2009 15:25:41 GMT Server: Apache/2.2.10 (Win32) PHP/5.2.8 Content-Length: 226 Connection: close Content-Type: text/html; charset=iso-8859-1 <!DOCTYPE HTML PUBLIC "-//IETF//D...

Position of least significant bit that is set

I am looking for an efficient way to determine the position of the least significant bit that is set in an integer, e.g. for 0x0FF0 it would be 4. A trivial implementation is this: unsigned GetLowestBitPos(unsigned value) { assert(value != 0); // handled separately unsigned pos = 0; while (!(value & 1)) { value >>= ...

process descriptor in kernel modules

Is it possible to get a pointer to process descriptor of a process in a kernel module?If it is possible pls post how? I need to find all files opened by a process and their offset values of each file descriptor.... ...

How does casting a function actually work in C?

int foo(char *c) {...} main() { int (*thud)(void *); thud = (int (*)(void *))(foo); } What actually happens during the evaluation of the assignment? There is a difference between the cast type and foo; the cast type is a pointer and foo is a function. So, does the compiler convert what's in '(foo)' into a pointer to foo ...

'comparison is always true due to limited range of data type' warning in C?

I have the following code //Point.h #define WIDTH 8 #define HEIGHT 8 typedef struct Point { char x; char y; } Point; //Board.c #include <stdbool.h> // Some other functions that we don't care about... bool inBounds(Point * p) { return p->x >= 0 && p->x <= WIDTH && p->y >= 0 && p->y <= HEIGHT; } When I compile th...

C to IEC 61131-3 IL compiler

I have a requirement for porting some existing C code to a IEC 61131-3 compliant PLC. I have some options of splitting the code into discrete function blocks and weaving those blocks into a standard solution (Ladder, FB, Structured Text etc). But this would require carving up the C code in order to build each function block. When l...

How do I align a number like this in C?

I need to align a series of numbers in C with printf() like this example: -------1 -------5 ------50 -----100 ----1000 Of course, there are numbers between all those but it's not relevant for the issue at hand... Oh, consider the dashes as spaces, I used dashes so it was easier to understand what I want. I'm only able to do this: --...

Black and White graphics context

I'm working in Quartz/Core-graphics. I'm trying to create a black and white, 1b per pixel graphics context. I currently have a CGImageRef with a grayscale image (which is really black and white). I want to draw it into a black and white BitmapContext so I can get the bitmap out and compress it with CCITT-group 4. (For some reason Quart...

log2 not found in my math.h?

I'm using a fairly new install of Visual C++ 2008 Express. I'm trying to compile a program that uses the log2 function, which was found by including using Eclipse on a Mac, but this Windows computer can't find the function (error C3861: 'log2': identifier not found). The way I understood it, include directories are specific to the IDE...

Why am I getting a segmentation fault with this code?

I am getting a segmentation fault while running this code. I can't work out why this is happening - can anyone see a possible reason? (I have already got and initialized the semaphore's shared memory.) My code: #include<stdlib.h> #include<sys/types.h> #include<sys/shm.h> #include<sys/ipc.h> #include<stdio.h> #include<...

Path to binary in C

How can I get the path where the binary that is executing resides in a C program? I'm looking for something similar to __FILE__ in ruby/perl/PHP (but of course, the __FILE__ macro in C is determined at compile time). dirname(argv[0]) will give me what I want in all cases unless the binary is in the user's $PATH... then I do not get the...