Building Macro from Parts

I'm working on a an AVR, and the libraries include device interrupt vectors like TCD0_OVF_vect and TCD0_CCA_vect using preprocessor #defines as follows:#define TCD0_OVF_vect_num 77#define TCD0_OVF_vect _VECTOR(77) /* Overflow Interrupt */They also include timer objects:typedef struct TC0_struct{ register8_t CTRLA; /* Control Register A */ ...snip...} TC0_t;#define TCD0 (*(TC0_t *) 0x0900) /* 16-bit Timer/Counter 0 */I want to be able to define a macro that will expand a named timer object, TCD0, to TCD0_OVF_vect using a syntax similar to VECT(TCD0, OVF_vect)....

Reuse modal dialog with different parent in GTK+ on MS Windows - broken focus

I'm reusing a modal dialog in GTK+ — I set it's parent dialog using gtk_window_set_transient_for, run it, and later reset it's parent to another dialog and run it again.On Linux everything is fine but on MS Windows the second time this dialog is displayed all GTK windows get confused which one is active.This is a test program:#include <gtk/gtk.h>GtkWidget* main_window;void run_reused_dialog( GtkWidget* reused_dialog, const gchar *parent_title, const gchar *reused_dialog_title) { GtkWidget* parent_dialog = gtk_dialog_new_with_buttons( parent_ti...

Find nearest RGB value using color palette array in C

I have some part of code done, but in some comparisons, nearest values are incorrectly.Example:Correct:Rgb value | Value from array0xFFFFFD = 0xFFFFFFIncorrect:Fixed codeRgb value | Value from array0xF4F939 = 0xFF0000 (should be 0xFFFF00)Console Output: (Correct)C:\Users\honguito\Desktop\Bat\Game_Batch_Files\24_to_8_bitmap>24_to_8_bit_paletteThe closest color of 0xFFFFFD is: '0xFFFFFF'C:\Users\honguito\Desktop\Bat\Game_Batch_Files\24_to_8_bitmap>Console Output: (Incorrect)C:\Users\honguito\Desktop\Bat\Game_Batch_Files\24_to_8_bitmap>24_to_8_bit_paletteThe closest...

Read mouse coordinates click in OpenGL

I'm trying to read the mouse coordinate when I click in a point on screen and mark It with a point, but It'isn't working. float cx = 0, cy = 0; glPushMatrix(); glPointSize(6.0f); //Draw the points glBegin(GL_POINTS); cx = (((x * (maxx + minx))) / width) + minx; cy = (((-1 * pow((y - height), width) * (maxy - miny)) / height ) + miny; glVertex2f(cx , cy); glEnd();glPopMatrix();It's a college exercise, and the formula to get the coordinate from screen is:Px and Py is the coordinate that mouseFunc pass to this function.w and h is the width...

User to read in numbers for an array of undefined size

I have this program:#include <stdio.h>#include <stdlib.h>int main(){ int i; int myArray[5]; printf("Enter some numbers for the array.\n\n"); for( i = 0; i < 5; i++ ) { scanf("%d", &myArray[i]); } printf("\nPrinting array...\n\n"); for( i = 0; i < 5; i++) { printf("%d \n\n", myArray[i] ); }}I want to modify my program to allow the user to enter as many numbers as they like and when they are done they can type "-1" which would then exit the scanf loop and move on in the program to print the array. The problem is that I...

Segmentation Fault on fclose

I am getting Segmentation fault error while running program in Linux. Working fine in AIX. And I get a seg fault with the message in gdb...Program received signal SIGSEGV, Segmentation fault fclose@@GLIBC_2.2.5 () from /lib64/libc.so.6 <pre><code> #include<stdio.h> #include<string.h> #include<unistd.h> #include<time.h> #include<sys/types.h> #define _Monthly "99992016" FILE *source,*list,*wlist,*movlist,*biflis; char sf[85],sf1[85]; ...

GTK+ 2.0 dynamic array

I am new to GTK+ and am writing in C using Eclipse. I have a couple of questions, if anyone can help I'll be more than thankful. I need to make a dynamic array of widgets (number of widgets can vary, like buttons or images). How can I achieve this? I am using table to align all, is it a good practice? I want all of the widgets to align vertically, 4 at a row; I am using Linux and I need to find all of the applications from application folder, use the "Icon" as an image and on click, execute the application. how can I do this using C with GTK+? Is there any way of making an ...

Image processing - Brightness and Contrast

I'm trying to adjust the brightness and contrast of an image. I had a look at the wiki article for conversions of RGB to HSL/HSV then adjusting and converting back, but that produces really weird outputs. So now I'm looking at other examples and it seems to be working fine.. The only problem is how can I adjust brightness and contrast at the same time?So say I have RGB of 100 100 100, then I want to adjust brightness to double and contrast to half... 2 and 0.5. How would I go about that? According to the second link, I would add 100 to all RGB values for brightness and then...

Save HBITMAP to *.bmp file using only Win32

I have a HBITMAP in my pure Win32 project (no external libraries are used). Can I export it to a *.bmp file using only Winapi and/or CRT functions so I don't incur any extra dependencies? There is no API to save into file directly because, generally, having a bitmap handle does not mean you have direct access to bitmap data. Your solution is to copy bitmap into another bitmap with data access (DIB) and then using it data to write into file. You typically either create another bitmap using CreateDIBSection, or you get bitmap data with GetDIBits.CreateFile, WriteFile write...

Inverting bitmap image turns the image black. But inconsistently

I am trying to negate a bitmap image with some code written in C. When I run the code for the Lena image (let me call it LenaImage1) the first time I get a black image (LenaImage2). When I run the same code on the image I get back the original image (LenaImage1). This implies that the code works correctly right? When I view and save (as bitmap) LenaImage2 using MATLAB I don't get the black image, meaning that I can see it as the complimented image(MATLAB returns the same output). And when I run the same C code on a second image (MountainImage1) I get a really bad image (Mou...

call matlab ifft from c

I have a short question: I would like to call the matlab fuction ifft from c code (inverse fast fourier transform)I was trying to understand the matlab api for c , but I could not find any example on how to pass the arguments or how to call an internal fuction of matlab within c codeany hint will be greatly appreciated ! Julia You can generate C code from a script using the MATLAB Coder app. That should make the ifft callable. The ugliest way to do it would be to exec() matlab and re-ingest its output. Oliver's answer is certainly the cleanest and best route though. ...

Additional variable in struct causes wrong return value in getter method

I'm very new to programming in C, but I have been using Java for years. I created a struct with two variables and a getter method (DFA_get_size) to return the value of one. However, when I added a third variable (the one commented out) the function DFA_get_size began to return the wrong number. I don't understand why this is happening. Please help.Below is the entire program.#include<stdio.h>#include <stdbool.h>typedef struct DFA { int nstates; //int trans; int ai;} DFA;extern DFA DFA_new(int nstates){ DFA dfa; dfa.nstates = nstates; dfa.ai = ...

What is "Signal 15 received"

What might cause a C, MPI program using a library called SUNDIALS/CVODE (a numerical ODE solver) running on a Gentoo Linux cluster to give me repeated Signal 15 received.?Is that code being issued by MPI, Sundials, Linux, C or who?Note that I am pretty much a beginner with the following technologies: C, MPI, SUNDIALS/CVODE, and Linux.I can find nothing that seems related by googling the message. I don't even know where to begin to look. (This is one of those questions where "anything helps" is to be taken quite literally.)(As an aside/afterthought why doesn't Chrome's dicti...

What's the RGB Color For the Windows COLOR_WINDOW or COLOR_BACKGROUND?

In the Windows Api and GDI, you can use the default window background color for drawing buttons and stuff (that slight greyish color on Win98 , WinXP + Classic Theme etc. ).What is the rgb value for that? So I can emulate the exact color in Allegro using al_map_rgb( r, g, b) ? It depends on the users settings.You should use GetSysColor function to retrieve the DWORD value and then use GetRValue, GetGValue, and GetBValue to retrieve red, green and blue component values. [XXX]Although Bobrovsky's answer (use GetSysColor) is likely the right solution to the actual proble...

C program not entering any for loops?

THIS IS A HOMEWORK ASSIGNMENTMy program seems to not be entering any for loops at all. At one point I had every function in main and was operating on 2 global variables without having to pass by reference or by value and everything was working correctly. Since then I have moved my functions out of main and am passing an array by reference and the length of that array into each function, I am getting printf statements that are outside of loops but nothing executes other than that.According to GDB my program exits with exit code 046.The program is simple, it takes a value to ...

C: List sort code not working

I cannot figure out why my code to sort the elements of a list does not work, it sort the first 5 element of the list and then just stop. I know it may be a stupid problem but I checked the loop a lot of time and can't understand why it reach the exit before the end of the list. typedef enum { NOTORD=0, TIME=1, POSITION=2 } ord_t;typedef struct elem { double position; double time; flag_t flag; struct elem * next;} elem_t;typedef struct { elem_t * head; int nelem; ord_t ord; } lista_t;void set_ordinata_time (lista_t * l) {if (l->ord!=TIME) { elem_t * aux, *co...

Page 1 of 312  |  Show More Pages:  Top Prev Next Last