c

Did I implement this correctly?

I'm trying to implement line thickness as denoted here: start = line start = vector(x1, y1) end = line end = vector(x2, y2) dir = line direction = end - start = vector(x2-x1, y2-y1) ndir = normalized direction = dir*1.0/length(dir) perp = perpendicular to direction = vector(dir.x, -dir.y) nperp = normalized perpendicular = perp*1.0/leng...

What is the explanation for "warning: assuming that the loop is not infinite"

I had just taken the decision to change as many variables from unsigned to int and upon recompiling the code in question, was greeted by this warning message: freespace_state.c:203: warning: assuming that the loop is not infinite The line in question: for (x = startx; x <= endx; ++x, ++xptr) This loop is 60 lines of code (inc white...

C: stdin and std* errs

I want to my manipulate Stdin, then Std* but some errs: $ gcc testFd.c testFd.c:9: error: initializer element is not constant testFd.c:9: warning: data definition has no type or storage class testFd.c:10: error: redefinition of `fd' testFd.c:9: error: `fd' previously defin...

how to create resources without VS C++ 2008 creating MFC files

I am creating a WIN32 application and I want most of all my application events to be made through the message queue. But everytime I create a dialog box or any resource like that. The IDE auto generates code that I don't necessarily need. I believe it's MFC code not sure. here it is. // dlgChangeDevice.cpp : implementation file // #in...

Correct initialization sequence for Linux serial port

I wrote an application that must use serial ports on Linux, especially ttyUSB ones. Reading and writing operations are performed with standard select()/read() loop and write(), and there is probably nothing wrong in them, but initialization code (or absence of some part of it) damages something in the tty subsystem. Here it is: vuxbo...

What's the difference between single and double quotes in Objective-C?

I'm working through a book exercise to generate some random serial number, and here's my function: NSString *randomSerialNumber = [NSString stringWithFormat:@"%c%c%c%c%c", '0' + random() % 10, 'A' + random() % 26, '0' + random() %...

Why am I getting a segmentation fault with this code?

Trying to make a simple rectangle/bin packer in C. Takes a given area and finds placement for any given size rectangle. About after 4 recursions is when I get the segmentation fault. #include <stdio.h> #include <stdlib.h> typedef struct node_type PackNode; struct node_type { int x , y; int width , height; int used; struct node_typ...

Algorithm to zoom into mouse(OpenGL)

I have an OpenGL scene with a top left coordinate system. When I glScale it zooms in from (0,0) the top left. I want it to zoom in from the mouse's coordinate (reletive to the OGL frame). How is this done? Thanks ...

Dereferencing within a buffer

Let's say I had a char pointer pointing to a buffer that contained these values (in hex): 12 34 56 78 00 00 80 00 I want to modify the last two bytes to a short value of 42. So I would think I would have to do something like this: (short)*(pointer+6)=42; The compiler doesn't complain but it does not do what I'm expecting it to do. ...

C: Proper syntax for allocating memory using pointers to pointers.

This is my first time posting here, hopefully I will not make a fool of myself. I am trying to use a function to allocate memory to a pointer, copy text to the buffer, and then change a character. I keep getting a segfault and have tried looking up the answer, my syntax is probably wrong, I could use some enlightenment. /* My objectiv...

GTK+ buffer in g_input_stream_read...

Hello, I load data with function: gssize g_input_stream_read (GInputStream *stream, void *buffer, gsize count, GCancellable *cancellable, GError **error); What is ma value of buffer parameter. How can I...

Ways to avoid Memory Leaks in C/C++

What are some tips I can use to avoid memory leaks in my applications? In my current project I use a tool "INSURE++" which finds the memory leak and generate the report. Apart from the tool is there any method to identify memory leaks and overcome it. ...

C: XNOR / Exclusive-Nor gate?

I am trying to find the most effective way of writing a XNOR gate in C. if(VAL1 XNOR VAL2) { BLOCK; } Any suggestions? Thanks. ...

Multitasking how to make worker thread gain control after calling infinite loop function

assume creating 3 worker threads by pthread_create, in these worker thread routine, each call a simple infinite loop function which do not have a return to do counting how to make worker thread gain control after calling infinite loop function and save the context of infinite loop function for calling in worker thread again? ...

how to clear stack after stack overflow signal occur

In pthread, After reaching yellow zone in stack, signal handler stop the recursive function by making it return however, we can only continue to use extra area in yellow zone, how to clear the rubbish before the yellow zone in the thread stack ? (Copied from "answers"): #include <pthread.h> #include <stdio.h> #include <stdlib.h> ...

How to find Unix system() function path in C

i am doing a project about shell, and i want the code that gives me the path the system() function uses. example, when i enter the command type dir the reply will be dir is external command (/bin/dir) this is what i reached, but its not working else if(strcmp(arg3[0],"type")==0) //if type command { if(strcmp(arg...

printing uid of a file on linux system

i am learning c programming. I am trying to make my own program similar to ls command but with less options.what i am doing is taking input directory/file name as argument and then gets all directory entry with dirent struct(if it is directory) . After it i use stat() to take all information of the file but here is my problem when i use...

C key pressed in Linux console

I have started to study C. I'm using Linux console and I would like to do a program which outputs random characters until ESC is pressed. How can I make such a keyboard handler? ...

C run function in another thread

Hello, I have simple from written on C/gtk+ and i have function in this appliction. I need to run this function in a separate thread from gui form. Where can i see example? Thank you. ...

Special parameters for texture binding?

Do I have to set up my gl context in a certain way to bind textures. I'm following a tutorial. I start by doing: #define checkImageWidth 64 #define checkImageHeight 64 static GLubyte checkImage[checkImageHeight][checkImageWidth][4]; static GLuint texName; void makeCheckImage(void) { int i, j, c; for (i = 0; i < checkImageHeig...