c

simple C problem

Hi, I have had to start to learning C as part of a project that I am doing. I have started doing the 'euler' problems in it and am having trouble with the first one. I have to find the sum of all multiples of 3 or 5 below 1000. Could someone please help me. Thanks. #include<stdio.h> int start; int sum; int main() { while (start < 1...

How does an array of pointers to pointers work?

char **Data[70]={NULL}; What is the correct terminology for this? How else could it be written? What does it look like in memory? I am reading many tutorials on pointers but I don't see it in this syntax. Any help is appreciated. Thanks. ...

how to fix a memory size for my application in C?

Hi, I would like to allocate a fixed memory for my application (developed using C). Say my application should not cross 64MB of memory occupation. And also i should avoid to use more CPU usage. How it is possible? Regards Marcel. ...

Passing pointers to function

Hi, I have a doubt in my program #include<stdio.h> int myFunc(char **); main() { char *a[2]={"Do","While"}; myFunc(a); } int myFunc(char **P) { /* Here I want to print the strings passed but I'm unable to print the strings I just tried the below statement which printed just the first letter which is 'D'*/ ...

Windows ring buffer without copying

On Ring Buffer's Wikipedia entry, there's example code showing a hack for UNIX systems whereby the adjacent virtual memory to a piece of memory is mapped to the same phbysical memory, thus implementing a ring buffer without the need for any memcpy, etc. I was wondering if there's a way to so something similar in Windows? Thanks, Fraser ...

Sample read/write handling of packets in C

I'm a bit new to C, but I've done my homework (some tutorials, books, etc.) and I need to program a simple server to handle requests from clients and interact with a db. I've gone through Beej's Guide to Network programming, but I'm a bit unsure how to piece together and handle different parts of the data getting sent back and forth. Fo...

How do I obtain, and synchronize, a complete list of all X11 windows?

I want to monitor all the open windows under X11. Currently, I'm doing this as follows: Initially walking the whole tree by recursively calling XQueryTree from the root window Listening for substructure changes on the whole desktop: XSelectInput( display, root_window, SubstructureNotifyMask | PropertyChangeMask ) Handling all MapNo...

Reference to Design Patterns in ANSI C?

Can you point me to a reference of design patterns in Standard C (C89 or C99)? (Not C#, not C++.) ...

Most significant 32 bits lost when casting pointer to int64_t

Can someone explain the following strange behavior? I run the following program on a 64-bit Intel platform: include <stdio.h> #include <stdint.h> int main(void) { int x; int *ptr = &x; printf("ptr = %p\n", ptr); printf("sizeof(ptr) = %d\n", sizeof(ptr)); int64_t i1 = (int64_t) ptr; printf("i1 = 0x%x\n", i1); printf("si...

Why is alloca not considered good practice?

Alloca allocates memory from Stack rather then heap which is case in malloc. So, when I return from the routine the memory is freed. So, actually this solves my problem of freeing up of dynamically allocated memory . Freeing of memory allocated through malloc is a major headache and if somehow missed leads to all sorts memory problems. ...

How to divide big numbers?

I have a big number (integer, unsigned) stored in 2 variables (as you can see, the high and low part of number): unsigned long long int high; unsigned long long int low; I know how to add or subtract some other that-kind of variable. But I need to divide that-kind of numbers. How to do it? I know, I can subtract N times, but, maybe, ...

Remote Desktop Protocol C or Objective-C Library

Does anyone know of a library for RDP that's written in C or Objective-C that is not GPLed? ...

Is there an easy way to convert an std::list<double> to a Python list?

I'm writing a little Python extension in C/C++, and I've got a function like this: void set_parameters(int first_param, std::list<double> param_list) { //do stuff } I'd like to be able to call it from Python like this: set_parameters(f_param, [1.0, 0.5, 2.1]) Is there a reasonably easy way to make that conversion? Ideally, I'd ...

Sandboxing in Linux

I want to create a Web app which would allow the user to upload some C code, and see the results of its execution (the code would be compiled on the server). The users are untrusted, which obviously has some huge security implications. So I need to create some kind of sandbox for the apps. At the most basic level, I'd like to restrict a...

Confused about memory locations of this Y86 assembly code

We had a piece of code in C in one class where we needed to convert it to Y86 and this was written on the board by some guy with the teacher's correction of course. However, I'm confusing the memory locations and .pos directives on the initial part of the code: int array[100], sum, i; int main() { sum = 0; for(i = 0; i < 100;...

Struct's contribution to type size

I am wondering why the following two types struct { double re[2]; }; and double re[2]; have the same size in C? Doesn't struct add a bit of size overhead? Thank you in advance. ...

Build errors w/ GLee (GL Easy Extension Library)

Using Code::Blocks w/ mingw, and trying to use GLee for some OpenGL on windows. I'm getting the following build errors: GLee.c|60|undefined reference to `_wglGetProcAddress@4' GLee.c|10748|undefined reference to `_wglGetProcAddress@4' GLee.c|10751|undefined reference to `_wglGetCurrentDC@0' GLee.c|10797|undefined reference to `_glGetStr...

C - element beyond the end of an array

I've been reading K & R's book on C, and found that pointer arithmetic in C allows access to one element beyond the end of an array. I know C allows to do almost anything with memory but I just don't understand, what is the purpose of this peculiarity? ...

Best C/C++ Libraries?

I have heard of Boost and ACE as two of the well known C++ libraries. What are the other good C/C++ libraries available? Does Boost and ACE support session management for web applications written in C/C++? EDIT: Ok I will try to be domain specific. I am looking for a C/C++ library which could help me maintain session state for a C++ b...

SendInput() Keyboard letters C/C++

I am trying to use SendInput() to send a sentence to another application (Notepad) and then send it hitting the Enter Key. Any code snippets? Or help ...