c

C Void pointer question

I have grep function in C( embedded programming ) that takes a void pointer as a parameter. the function needs to be able to handle different kinds of types of variables like chars ints and longs. How can I code the function so it can figure out by itself what type of variable i am passing ?? I dont know if this is possible. thanks ie. ...

Organizing C code in my Xcode project

I want to include a few straight C functions in my Objective C project. Simple stuff like this: CGPoint vectorSum (CGPoint point1, CGPoint point2) { return CGPointMake(point1.x+point2.x, point1.y+point2.y); } What is the best way to keep things organized? In particular, I notice that when I go to create a .c file, it gives me ...

Fastest way of doing transformations (Move, Rotate, Scale)

I was looking at this vector drawing application called Creative Docs .Net . I noticed that I can have hundreds of shapes and moving, rotating and scaling do not lag at all. Given that all verticies must be modified, how do applications generally do these transformations as quickly as possible? Thanks ...

Last inserted row with sqlite3 and C

Hi folks, I wrote a kind of key/value store using sqlite3 and C. my put_pair(key, value) function accepts an empty key as a correct key, and in my INSERT query I use lower(hex(randomblob(16))) to generate a good key for this inserted row. The problem now is how to retrieve this key and return it by my function? ...

Installing OpenGL/GLUT & running C program?

I'm new to OpenGL and GLUT and need help installing them and running hello.c (see below) in Visual C++ 2010 Express Edition. I'm using Windows XP and was reading on the OpenGL wiki that the OpenGL Library is already installed on my computer. As a result, I only downloaded GLUT for Win32 dll, lib and header file and extracted it. I hav...

Set the backcolor of a WinAPI toolbar with Visual Styles?

Is there a way to set the background color. I thought of making a dummy window and then using TBSTATE_TRANSPARENT, but I thought there might be a cleaner solution? Thanks None of these solutions work for a toolbar using visual styles ...

C CGI Program: how to print dynamically?

Hello I am new to CGI programming in C. What I'm looking to do is, per the title, print things dynamically. For instance, consider this code that prints out a bunch of numbers: int main() { long int l=0; printf("Content-Type: text/plain;charset=us-ascii\n\n"); while(1) { printf("%li ", l); if (...

How do I convert from void * back to int

if I have int a= 5; long b= 10; int count0 = 2; void ** args0; args0 = (void **)malloc(count0 * sizeof(void *)); args0[0] = (void *)&a; args0[1] = (void *)&b; how can I convert from args[0] and args0[1] back to int and long? for example int c=(something im missing)args0[0] long d=(something im missing)args1[0] ...

Algorithm to divide a rectangle to smaller retangles?

What's the algorithm to divide a rectangle (c struct with 4 ints) to a random number of smaller rectangles (return a list of structs)? Even better if the max and min dimension of the smaller rectangles can be controlled by a parameter. e.g. +----------+ +-------+--+ | | | | | | | ...

Why is my cursor infinitely looping on the last row

Hello I've been trying to use a cursor with embedded sql in c but I can't seem to get it to stop reading the last row in my table. The table is called publication with two attributes pubid and title. I just want my cursor to iterate through and display the pubid. This is what i have: EXEC SQL DECLARE C1 CURSOR FOR SELECT pubid FRO...

casting from binary to multi-dimensional array on heap

i'm currently using binary files for quick access to custom objects stored in multidimensional arrays which are saved to file as object arrays. so far, reading from file hasn't been too much of a problem since i've been reading the array into an identical object array on the stack. it looks something like this: Foo foo[5][10]; ifstream ...

How to read TENTATIVE flag of IPv6 Address ?

I am assigning ipv6 address using ioctl() system call prgramtically. I want to know if there is a way, i can find the assigned ip is tentative/duplicate ? Thanks. ...

Libraries for standard stuff (ie: cout, etc) *NEWBIE QUESTIONS* :)

Hello everyone. I was wondering about the standard C libraries that contain all the functions/definitions like abs(), cout streams, printf, etc. I'm familiar with the header files (stdio.h, cmath.h, time.h, etc etc) but there doesn't seem to be any corresponding .lib or .dll anywhere (ie. stdio.lib, time.dll, etc). Where is the actual...

How to create function for FFmpeg lib to encode frame into any (possible) format?

So how to create something which would have something like this in its api: Encoder = EncoderFormat(format name); // prepare encoder //...code for frames generation... now we want to encode frame!// EncodeFrame(const CImage* src, void* dest, int* is_keyframe, more args if needed); Is it possible? Please could any one provide simple ex...

What is CHAR_BIT?

From http://graphics.stanford.edu/~seander/bithacks.html: int v; // we want to find the absolute value of v unsigned int r; // the result goes here int const mask = v >> sizeof(int) * CHAR_BIT - 1; r = (v + mask) ^ mask; Patented variation: r = (v ^ mask) - mask; What is CHAR_BIT and how use it in programming languages? c...

memmove leaving garbage - C

I wrote the following function to split the given full path into directory, filename and extension. #include <stdio.h> #include <string.h> #include <stdlib.h> struct path_info { char *directory; char *filename; char *extension; }; #ifdef WIN32 const char directory_separator[] = "\\"; #else const char directory_separator[]...

Mem leak in image loader

Hello, I have a function for loading GdkPixbufAnimation from stream. GdkPixbufAnimation* load_image_from_stream(GInputStream* input_stream, GCancellable* generator_cancellable) { GError** error; gboolean res; gssize n_read; guchar buffer[65535]; GdkPixbufAnimation* animation; GdkPixbufLoader* loader; loader = gdk_pixbu...

How does the decimal accuracy of Python compare to that of C?

I was looking at the Golden Ratio formula for finding the nth Fibonacci number, and it made me curious. I know Python handles arbitrarily large integers, but what sort of precision do you get with decimals? Is it just straight on top of a C double or something, or does it use a a more accurate modified implementation too? (Obviously not...

Simple and effective way to stall a program

I have a program that sets a global keyboard hook and handles key presses. This is my WinMain: int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PSTR pCmdLine, int nCmdShow) { MSG msg; logFile = fopen("C:\\keylog.txt", "w"); hKeyHook = SetWindowsHookEx(WH_KEYBOARD_LL, (HOOKPROC)KeyEvent, GetModuleHandle(NULL), 0); ...

How to convert a c string into its escaped version in c?

Is there any buildin function or a alternative simple and fast way of escape a C character array that if used with e.g printf should yield original character array again. char* str = "\tHello World\n"; char* escaped_str = escape(str); //should contain "\tHello World\n" with char \ ,t. printf(escaped_str); //should print out [TAB]Hello W...