c

SWIG for making PHP extensions, have you tried it?

I have a few small libraries and wrappers written in C (not C++) that I would like to make available to PHP via extensions. I read several tutorials on writing proper PHP extensions and it does not seem to difficult, however I don't want the hassle of maintaining the extensions in addition to the libraries. I read that SWIG supports bui...

Basic unit test and C, how do I get started?

Hi After reading quite some threads here at StackOverflow, I have come to the conclusion that I should adopt to some form of test driven development/unit test (or at least explore the area). And since we are talking about c code under Linux, I decided to give check a try (I don't know if this is the right choice but if it's no goo...

Difference in initalizing and zeroing an array in c/c++ ?

In c (or maybe c++) , what's the difference between char myarr[16]={0x00}; and char myarr[16]; memset(myarr, '\0', sizeof(myarr)); ?? edit: I ask this because in vc++ 2005 the result is the same.. edit more : and char myarr[16]={0x00,}; ? maybe can get more comprehensive answer and not ambigous as some answers below re...

Which numerical values do the F-Keys ( F[1-12]) and the Arrow-keys have?

I'd like to write an application in C which uses arrow-keys to navigate and F-keys for other functions, such as saving to a file, language selection, etc. Propably the values depend on the platform, so how could I find out which values the keys have? If they don't, or if you know them, I don't have to know how to find out;) Edit: My p...

Is returning a pointer to a static local variable safe?

I'm working with some code that widely uses the idiom of returning a pointer to a static local variable. eg: char* const GetString() { static char sTest[5]; strcpy(sTest, "Test"); return sTest; } Am I right in thinking that this is safe? PS, I know that this would be a better way of doing the same thing: char* const GetString...

How to: Java listening for events captured by C thread.

I would like to create a Java program to listen for and respond to events captured by a thread in C. Can someone explain how this can be achieved using JNI, or point me to online tutorials? Thank you. ...

Is there a listing of the POSIX API / functions?

I'm trying to find out where I can find documentation on POSIX functions, but coming up short. Any recommendations? EDIT: I asked this because we're strictly limited to POSIX compliant functions for this assignment. ...

Creating big file on Windows

Hi, I need to create big relatively big (1-8 GB) files. What is the fastest way to do so on Windows using C or C++ ? I need to create them on the fly and the speed is really an issue. File will be used for storage emulation i.e will be access randomly in different offsets and i need that all storage will be preallocate but not initia...

Detecting WAN radio power off

Like most laptops, mine (a Dell Inspiron 1420) has a small button which can be used to turn the wifi card on and off. Is there any way to detect that the radio has been turned off in a Win32 C program or service? I'm looking for a better way than to get the list of the visible access points, something that only depends on the state of th...

Formating file on windows

Hi, Following my question about creating files. After fast creation of large file, now i need to create a file system on this file. How can i create something like Loop device on Linux. After this i guess formatting will be really easy. Any alternative method (instead mounting) for formatting file to different FAT (12/32) and ext3 are ...

dynamic allocating array of arrays in C

I don't truly understand some basic things in C like dynamically allocating array of arrays. I know you can do: int **m; in order to declare a 2 dimensional array (which subsequently would be allocated using some *alloc function). Also it can be "easily" accessed by doing *(*(m + line) + column). But how should I assign a value to an ...

Code Ordering in Source Files - Forward Declarations vs "Don't Repeat Yourself"?

If you code in C and configure your compiler to insist that all functions are declared before they are used (or if you code in C++), then you can end up with one of (at least) two organizations for your source files. Either: Headers Forward declarations of (static) functions in this file External functions (primary entry points) Stati...

How to validate input using scanf

How can I validate the user input by using scanf. Right now I have something like this, but doesn't work. NOTE: I have the atoi just to validate that the scanf validation works. scanf("%[0987654321.-]s",buf); i = atoi(buf); if(i) index = i; ...

ANSI Color extraction library in C/Objective-C

I'm seeking a library, or bit of code I can incorporate into a Cocoa project where I can turn a stream of text with ansi color control codes into an attributed string. There are many projects that do this, but having examined their code they're either messy or overly complex. Has anyone an idea of a simple piece of code, or library, or...

How can I print out string records stored in a two-dimensional array?

I am working on a project using C. I store several records in a two-dimensional array of strings, where one string is the record name and the other string is the actual value. For example: myArray[0][0] = "filename1"; myArray[0][1] = "somefile.txt"; myArray[1][0] = "filename2"; myArray[1][1] = "anotherfile.txt"; // and so on ... I kno...

GMP can't cope with a leading "+"?

Consider the following code // BOGP.cpp : Defines the entry point for the console application. // #include "stdafx.h" #include "gmp-static\gmp.h" #include <stdlib.h> /* For _MAX_PATH definition */ #include <stdio.h> #include <malloc.h> #define F(x) mpf_t x; mpf_init( x ); int main(int argc, char* argv[]) { F(foo); char * b...

Code to utilize memory more than 70%

Please tell me C++/Java code which utilize memory more than 70% . For Example we have 3 Virtual machine and in memory resources we want to test the memory utilization as per memory resources allocated by user. ...

How to display text in system tray icon with win32 API?

Trying to create a small monitor application that displays current internet usage as percentage in system tray in C using win32 API. Also wanting to use colour background or colour text based on how much is used relative to days left in month. EDIT: To clarify I am wanting the system tray icon to be dynamic. As the percentage changes ...

Where to start (self-)learning C, or should I learn I learn a different language?

Lately, I discover more and more that it's good to have extensive knowledge of programming fundamentals. Sadly, I am (one of the many) self-taught PHP developers and have no regrets choosing that path. However, I still think I should extend my knowledge to some "real" programming languages starting from zero and build up my knowledge fr...

Does restrict help in C if a pointer is already marked const?

Just wondering: When I add restrict to a pointer, I tell the compiler that the pointer is not an alias for another pointer. Let's assume I have a function like: // Constructed example void foo (float* result, const float* a, const float* b, const size_t size) { for (size_t i = 0; i < size; ++i) { result [i] = a [0] * ...