c

Measure time in minutes in C

I am writing a program that will need to measure time in minutes. To be exact, it will wait 10 minutes, execute some code, wait 2 minutes, execute more code and repeat this 5 times (anyone guess what I'm trying to do?) and I am wondering how to do the breaks. Thanks in advance! Oh, and by the way, I'm on Mac. ...

Screen capture code produces black bitmap

I need to add the ability to take a screenshot of the entire screen, not just the current window. The following code produces a bmp file with the correct dimensions, but the image is completely black. What am I doing wrong? void CaptureScreen(LPCTSTR lpszFilePathName) { BITMAPFILEHEADER bmfHeader; BITMAPINFO ...

segmentation fault

int num_arrays; char *p[20]; char tempc; int i=0; do { p[i]=malloc(sizeof(int)); scanf("%s",p[i]); tempc=*p[i]; ++i; }while(tempc=='x'); num_arrays=atoi(p[0]); When i write num_arrays=atoi(..),gcc give me segmentation fault or memory stack is exce...

What does printf return?

Today in my interview, the interviewer asked: printf is a function and every function returns something; int, void, float, etc. Now what does printf return as it's a function? ...

SWIG & C/C++ Python API connected - SEGFAULT

Hello, my task is to create dual program. At the beginning I start C program that calls throught C/C++ API of Python some Python method. The called method after that call a function that is created with SWIG. I show you my sample also with backtrace from gdb after I am given Segmentation fault. main.c: #include <Python.h> #include <s...

C header file won't compile with C, but will with C++.

I have the following chunk of a header file BKE_mesh.h: /* Connectivity data */ typedef struct IndexNode { struct IndexNode *next, *prev; int index; } IndexNode; void create_vert_face_map(ListBase **map, IndexNode **mem, const struct MFace *mface, const int totvert, const int totface); void create_vert_edge_map(ListBas...

Read a file with a specific encoding in C?

Hi, I've a file that was written on windows with encoding WINDOWS-1256, and I need to write a C program that reads bytes from this file and write them back to a new file with UTF-8 encoding. How to read a file with a specific encoding in C ?? ...

va_arg with pointers

I want to initialize a linked list with pointer arguments like so: /* * Initialize a linked list using variadic arguments * Returns the number of structures initialized */ int init_structures(struct structure *first, ...) { struct structure *s; unsigned int count = 0; va_list va; va_start(va, first); for (s = f...

Microbenchmark showing process-switching faster than thread-switching; what's wrong?

I have two simple microbenchmarks trying to measure thread- and process-switching overheads, but the process-switching overhead is turning out to be lower than that of thread-switching, which is unexpected. The setup: 1.8GHz Core 2 Duo, 2GB RAM, Linux 2.6.32-21-generic x86_64 (Ubuntu 10.04). I'm getting: ~2.1-2.4us per process switch ~...

Function defined but not used warning in C

I have a number of C source files(both .c and .h files). header files contains a number of functions. Out of those functions, only partially are used in a source .C file.Suppose a.h,b.h are header files and a.c and b.c are .c files. a.h is included in a.c. But only a number of functions those are in a. h are used and rest are not used...

binary files writing/reading problems...

Ok i have problem with my code for reading binary file... First i will show you my writing code: void book_saving(char *file_name, struct BOOK *current) { FILE *out; BOOK buf; out = fopen(file_name, "wb"); if(out != NULL) { printf_s("Writting to file..."); do { if(current != NUL...

Linked list in C

I am still new at lists in C and i got a big problem... First i wanna show you my code for inserting item to the list: void input_books_info(int number_of_books, BOOK *current) { int i; for(i = 0; i < number_of_books; i++) { while(current->next != NULL) current = current->next; current->next = (...

How to debug anomalous C memory/stack problems

Hello, Sorry I can't be specific with code, but the problems I am seeing are anomalous. Character string values seem to be getting changed depending on other, unrelated code. For example, the value of the argument that is passed around below will change merely depending on if I comment out one or two of the fprintf() calls! By the la...

atol(), atof(), atoi() function behaviours, is there a stable way to convert from/to string/integer ?

In these days i'm playing with the C functions of atol(), atof() and atoi(), from a blog post i find a tutorial and applied: here are my results: void main() char a[10],b[10]; puts("Enter the value of a"); gets(a); puts("Enter the value of b"); gets(b); printf("%s+%s=%ld and %s-%s=%ld",a,b,(atol(a)+atol(b)),a,b,(atol(a)-atol(b))); ge...

Creating a menustrip in WinAPI?

Is there a way to get a menustrip instead of an HMENU when using the WinAPI? Like menus that .Net applications use? Because the HMENU just doesn't fit my color scheme, I need a darker menu. Thanks ...

Testing for the presence of a character in an string in C

What's wrong with this? #include <stdio.h> void main(){ char *s="some text"; printf("%d",is_in(s,'t')); } int is_in(char *s, char c){ while(*s){ if(*s==c) return 1; s++; } return 0; } I get the following compile time error with GCC: test.c:9: error: conflicting types for ‘is_in’ test.c:9: note:...

Why address of a variable change after each execution in C?

int i=10; printf("Address of i = %u",&i); Output: Address if i = 3220204848 Output on re-execution: Address of i = 3216532594 I get a new address of i each time I execute the program. What does this signify? ...

Makefile to compile both C and Java programs at the same time

I have three programs that need to be compiled at the same time, 2 written in C and 1 in java. I had all three working with the Makefile when they were in C, but then switched one of them to java... is there a way to compile all 3 at once with the same makefile? Here is my current Makefile: CC=gcc JC=javac JFLAGS= -g CFLAGS= -Wall -...

Newbie question: How to create and use static libraries in WINARM?

I'm using WINARM Version 20060606 located here: http://www.siwawi.arubi.uni-kl.de/avr_projects/arm_projects/#winarm I want to create a simple static library as follows: ---- plus.h ------------ int plus(int x, int y); ---- plus.c ------------ #include "plus.h" int plus(int x, int y) { return (x + y); } Then I want to sta...

wii motionplus support

hello, I am developing a PC application that interacts with the Wii Remote. So far I have been using the wiiuse library, which has worked great. However wiiuse does not support the MotionPlus extension. I have heard of extensions to implement this by Dolphin and libogc but have not managed to locate this code. Do you know of code that...