c

Alternative for windows fullpath API which can take path greater than 255 characters!

_fullpath API of windows takes relative path and gives the corresponding absolute path. But, it fails if the relative path is greater than 255 characters. Is there any other API available in Windows which can convert the relative path to absolute path and doesn't have the problem mentioned above? ...

How to count the "white" correctly in mastermind guessing game in c?

“White" is the checking of correct number at wrong position. But I don't know how to count it correctly. #include "stdafx.h" #include "stdlib.h" #include "time.h" int _tmain(int argc, _TCHAR* argv[]) { int answer[4]; int guess[4]; int count = 0; srand(time(NULL)); /*answer[0] = (rand() % 6)+1; answer[1] = (ra...

What data structure for O(1) random insertion/deletion and O(1) random access?

I don't know what data structure to use for this problem. I want the structure to have: Constant time insertion or deletion. Constant time retrieval by id. The actual system is: I've got a bunch of objects each with a unique id. My program will need to receive requests for an id and return the relevant object. Whenever it receives...

Limiting the features of an embedded python instance

Is there a way to limit the abilities of python scripts running under an embedded interpretor? Specifically I wish to prevent the scripts from doing things like the following: Importing python extension modules (ie .pyd modules), except those specifically allowed by the application. Manipulating processes in any way (ie starting new pr...

Linking MTL (Matrix Template Library) in Visual Studio

I have MTL header files; I want to use those header files in Visual Studio 2008. How can I link those header files so that I can write a matrix program using the MTL library? ...

Tool for detecting pointer aliasing problems in C / C++

Is there a tool that can do alias analysis on a program and tell you where gcc / g++ are having to generate sub-optimal instruction sequences due to potential pointer aliasing? ...

Image loading, C language and GTK

I keep getting a broken image (a red 'X' in a paper, it doesn't even start loading the one i want, I don't know if this is clear enough) and don't know why, here is what i tried: image = gtk_image_new_from_file("abc.png"); gtk_container_add (GTK_CONTAINER (window), image); gtk_widget_show (image); gtk_widget_show (window);` I am a new...

Print Hexadecimal Numbers Of a File At C And C++

I'm now developing a home project, but before I start, I need to know how can I printcout the content of a file(*.bin as example) in hexadecimal? I like to learn, then a good tutorial is very nice too ;-) Remember that I need to develop this, without using external applications, because this home project is to learn more about hexadeci...

Which would you prefer to have to maintain?

[To any mod considering deleting this question - please don't. Either my or Steve Jessop's code may well be helpful to reference from questions regarding reading text files using C.] This question has generated the usual amount of sound and fury re the relative merits of C and C++. But something that never seems to get introduced into t...

Why does Eclipse fail on this scanf() command when the Command Prompt executes it fine?

I'm new to C. Here's my code: /* Using scanf() */ #include <stdio.h> int main(void) { int iDec1, iDec2, iDec3; printf("Enter three decimals:\n"); scanf("%d,%d,%d", &iDec1, &iDec2, &iDec3); printf("Your decimals are %d, %d and %d.", iDec1, iDec2, iDec3); return 0; } It works in the Command Prompt, but when I run it...

Exit function On Linux

When reading/writing a file in my application, I want to exit(1) if the file is not closed correctly. On Windows it works well, but on Linux this error appears: ‘exit’ was not declared in this scope How can I solve that? Thanks. ...

Writing Secure C and Secure C Idioms.

"The average man does not want to be free. He simply wants to be safe." - H. L. Menken I am attempting to write very secure C. Below I list some of the technics I use and ask are they as secure as I think they are. By all means, please don't not hesitate to tear my code/preconceptions to shreds. Any answer that finds even the most t...

How to write a file with C in Linux?

I want to rewrite the "cp" command of Linux. So this program will work like #./a.out originalfile copiedfile. I can open the file, create new file but can't write the new file. Nothing is written. What could be the reason? The current C code is: #include <stdio.h> #include <sys/types.h> #include <sys/stat.h> #include <fcntl.h> #include...

Why doesn't this code sort lines containing numbers correctly?

I'm looking at this program that reads input lines and then sorts them, from K&R. And I can't figure out why it doesn't sort them correctly if I enter for example 1234532 first line abc second line It won't sort them in increasing order. Basically it doesn't work if the input lines contains numbers or something other then letters, I ...

Git client on the iPhone, possible? How?

Is it possible to embed git in the iPhone app? Only in a passive mode, i.e. to be able to read commit messages (with date and user) and diffs given some online git repository in order to present it in some readable table views? ...

Bootstrapping a language on LLVM

I'm bootstrapping a programming language compiler on top of LLVM. Currently I'm mostly done writing a compiler for a subset of C which is self-compiling. When I'm finished with that, I'll bootstrap my language away from C, maintaining self-compilation as I go. Since the compiler is self-compiling, any features of C that I use I will h...

How to load a shared library without loading its dependencies?

Say I have a library libfoo.so.1, which depends (according to ldd) on libbar.so.1. However, libbar.so.1 is not available at the moment. My app needs to call a function in libfoo.so.1 which doesn't require libbar.so.1 at all. Is there a way to load libfoo.so.1, resolve the function symbol and then call it without having libbar.so.1 to sa...

Are comments always processed before the preprocessor?

/* #define FOO */ #ifdef FOO #define BAR "pirate" #else #define BAR "ninja" #endif int main() { printf(BAR); getchar(); } In this code FOO is not defined (Visual Studio 2008). I assume that comments are processed first, then preprocessor, and then code. Are comments always processed before the preprocessor? Is this part of a standar...

Explanation required for BITCOUNT macro

Can someone explain how this works? #define BX_(x) ((x) - (((x)>>1)&0x77777777) \ - (((x)>>2)&0x33333333) \ - (((x)>>3)&0x11111111)) #define BITCOUNT(x) (((BX_(x)+(BX_(x)>>4)) & 0x0F0F0F0F) % 255) Clarification: Ideally, the...

How to acess ctime, mtime, … of a symbolic link?

On unix symlinks are pointers to another file. Not only the file but also the symlink has a ctime, mtime, …. I know the symlinks time can be accessed, as ls displays it. If I use one of ruby's File#ctime, File#mtime, …, I always get the attribute of the file the symlink is pointing to, not of the symlink. How can I read this values in ru...