c

Simple way to extract part of a file path?

I'm not very good at C, and I always get stuck on simple string manipulation tasks (that's why I love Perl!). I have a string that contains a file path like "/Volumes/Media/Music/Arcade Fire/Black Mirror.aac". I need to extract the drive name ("Media" or preferably "/Volumes/Media") from that path. Any help would be greatly appreciate...

reading a text file into an array in c

What would be the most efficient method of reading a text file into a dynamic one-dimensional array? reallocing after every read char seems silly, reallocing after every read line doesn't seem much better. I would like to read the entire file into the array. How would you do it? ...

"#include" a text file in a C program as a char[]

Is there a way to include an entire text file as a string in a C program at compile-time? something like: file.txt: This is a little text file main.c: #include <stdio.h> int main(void) { #blackmagicinclude("file.txt", content) /* equiv: char[] content = "This is\na little\ntext file"; */ printf("%s", content); } o...

Coding style checker for C

I'm working for a company that has strict coding style guidelines but no automatic tool to validate them. I've looked around and the only tools I could find were lint like tools that seem to be aimed at verifying what the code does, and preventing bugs and not at making sure the coding style is correct. What tool should we use, if at al...

Tutorial for tile based side scroller game-play?

Does anyone know a good resource or some pointers which could help me make a side scrolling tile based (descreet movement for character) with box pushing and moving platforms etc. I'm focused right now C/C++ console development (tho after this project I may stop and do stuff a little more graphical, still C/C++). Something bit like Super...

Addressing splint warnings about functions "not used" while they are passed as parameters

On a program of me, the splint checker warns: expat-test.c:23:1: Function exported but not used outside expat-test: start A declaration is exported, but not used outside this module. Declaration can use static qualifier. (Use -exportlocal to inhibit warning) expat-test.c:38:1: Definition of start The start() function is used. T...

Getting the Program Process ( Service and Daemon ) on Linux in C

I'd like to know how one would create an application that starts in the background. Im currently creating a Webserver in C as a little project, both to learn some old C and Linux Socket Programming. But my current concern is; How do i get the current process number? I want to get this because when i start the process, i want to displa...

Converting 32-bit Application Into 64-bit Application in C

I am presently working on converting a 32bits application into a 64bits application in C. This application is currently working on x86 architecture (Windows, osx, Unix, Linux). So, before starting coding, I wanted to know what do I need to consider while converting the application. ...

uncompress .Z file in C

Can someone point me to a public domain (or MIT- or BSD-license) library for decompressing .Z files in ANSI C? Thanks! ...

File based Configuration handling in C ( Unix )

This is probably one of the most common tasks / problems when programming; You need to store the configuration of your application somewhere. While im trying to create a webserver and / or other applications, I'd like to keep the code as clean as possible since my main interest in programming is Architecture. This results in me wanting ...

Windows Beep() equivalent for Linux

I am experimenting with Beep function on Windows: #include <windows.h> ... Beep(frequency, duration); The computer then beeps with some frequency for some duration. How would I do this on a Linux computer? Edit: It IS important to output different frequencies. ...

Is there a good Valgrind substitute for Windows?

I was looking into Valgrind to help improve my C coding/debugging when I discovered it is only for Linux - I have no other need or interest in moving my OS to Linux so I was wondering if there is a equally good program for Windows. ...

Propagating C++ exceptions across C stack frames on OS X

Hello everyone, The application I'm working on (it's a game, actually) uses XML for some of its configuration. Since I'm using CEGUI for the GUI, and it has its own XML parsing objects, I converted my code to use that instead of my own hand-rolled parser class. If the document is missing attributes on certain tags, it throws an except...

Object-Orientation in C

Can someone please share a set of nifty preprocessor hacks (ANSI C89/ISO C90 compatible please) which enable some kind of ugly (but usable) object-orientation in C? I am familiar with a few different object-oriented languages, so please don't respond with answers like "Learn C++!". I have read "Object-Oriented Programming With ANSI C" (b...

Stubbing functions in simulations

I'm working on an embedded C project that depends on some external HW. I wish to stub out the code accessing these parts, so I can simulate the system without using any HW. Until now I have used some macros but this forces me to change a little on my production code, which I would like to avoid. Example: stub.h #ifdef _STUB_HW #define ...

String as array index in C

Hi, Can a string be used as array index in C? Ex: String Corresponding value "ONE" 1 "TWO" 2 "FIVE" 5 "TEN" 10 When a string in the above list is passed to the function, the function must return the corresponding value indicated above. Can this be achieved by declaring a constant array with string as index ...

Help with basic threading concept / race conditions

I'm learning about POSIX threads right now, but I guess this is just a general question on multithreading, so I hope that anyone can help me. I have this example from the book that I am working on which demonstrates a race condition: void *thread_main(void *thread_number) { printf("In thread number %d.\n", *(int *)thread_number); } ...

is f(void) deprecated in modern C and C++

I'm currently refactoring/tidying up some old C code used in a C++ project, and regularly see functions such as int f(void) which I would tend to write a int f() Is there any reason not to replace (void) with () throughout the codebase in order to improve consistency, or is there a subtle difference between the two that I am unaw...

What to put in a binary data file's header

I have a simulation that reads large binary data files that we create (10s to 100s of GB). We use binary for speed reasons. These files are system dependent, converted from text files on each system that we run, so I'm not concerned about portability. The files currently are many instances of a POD struct, written with fwrite. I need...

Empty _ASSERTE Dialog Box from ISAPI Extension

I have an ISAPI extension DLL written in C++ using Microsoft Visual Studio 2003 running in IIS 5.1 on XP Pro. Whenever an _ASSERTE fires I just get a an empty message box with 'Error' in the title bar and Abort/Retry/Ignore buttons. What I don't see is any of the expression text from the _ASSERTE macro. I've traced into the runtime libra...