c

How to store a version number in a static library?

How can I store a version number in a static library (file.a) and later check for its version in Linux? P.S. I need possibility to check version of file any time without any special executable using only by shell utilities. ...

Given an angle and length, how do I calculate the coordinates

Assuming the upper left corner is (0,0) and I'm given an angle of 30 degrees, a starting point of (0,300), a line length of 600, how do I calculate the ending point of the line so that the line is representative of the angle given. The C pseudo-code is main() { int x,y; getEndPoint(30, 600, 0, 300, &x, &y); printf("end x=%d, en...

Transfer file in blocks

In C (UNIX), how can I transfer and receive a file in multiple blocks using a socket? For example, if I had a file of 1234 bytes, and a block size of 500, I would transfer: 500 bytes, then 500 bytes, then 234 bytes I have attempted this using fseek, read, write, but I just cannot get the logic right. Even a good reference would b...

linux threads and fopen() fclose() fgets()

I'm looking at some legacy Linux code which uses pthreads. In one thread a file is read via fgets(). The FILE variable is a global variable shared across all threads. (Hey, I didn't write this...) In another thread every now and again the FILE is closed and reopened with another filename. For several seconds after this has happened,...

listing shared memory objects on Solaris by name

I can use ipcs(1) to list out the active shared memory objects on a Solaris 10 box, but it lists them by key. I'm opening the objects via shm_open(3), though, which takes a character string as a name to identify the object. Is there a way to list the shared memory objects by name, or to just get the key<->name mapping? I'm mostly inte...

c malloc questions (mem corruption)

When using malloc, if it produces a core dump with the error: malloc(): memory corruption: ....... *** Does this mean that malloc tried to allocate memory that was not free to allocate? IF so what are the causes of this? ...

Linking to MATLAB generated code

I'm using embedded MATLAB to generate C code from an .m script. However, after the generation I'm left with about 15 files (most of them are source). If I want to write a standalone main in C how do I link to the MATLAB generated code? Is there a way to do this without writing my own Makefile? So I figured out how to generate stati...

Best way to setup a Windows build environment for C/C++

Basically I want to compile C/C++ using the GCC on Windows. The two competing platforms, as i see it, are MinGW and Cygwin. Each have their own benifits and limitations. MinGW compiles for Windows, whereas Cygwin needs the cygwin .dll. However installing libraries on MinGW is difficult, whereas on cygwin it's easier, using the setup.exe ...

C Code layout and how to separate different sections of code?

In a C code, how you separate different sections of code, for example Implementation, Globals, etc? Is there a coding standard. I have seen many methods, but which one is preferred, I want to get community opinions on this.. /********************************************************* * GLOBALS ...

Debugging SQLite statements

I have this SQL statement running on my database and I'm sure it's right, but it's not making any change to the database. How can I debug it? The query: UPDATE task SET name=?, description=?, startDate=?, dueDate=?, complete=?, status=?, percentComplete=?, taskType=? WHERE rowId=:rowId I conditionally bind the first 8 parameters dep...

When should you use macros instead of inline functions?

In a previous question what I thought was a good answer was voted down for the suggested use of macros #define radian2degree(a) (a * 57.295779513082) #define degree2radian(a) (a * 0.017453292519) instead of inline functions. Please excuse the newbie question, but what is so evil about macros in this case? ...

Select a function at compile time

Hi, in my C project I have five different function (with the same name) which implement one algorithm but in different ways. At compiler time I need to select only one of these functions. Can I implement this using a #define and a bunch of #ifndef? Are there better ways to do this? ...

GL fragment shaders 101

I want to add a GLSL fragment shader to a program of mine, however I have been unable to find comprehensive documentation related to the C language (not C++ or C#). Anyone has examples or steps to get the ARB extension for shaders, or some sort of "hello world" template? I don't need help on the shaders themselves, just how to get them ...

c expression evaluator take 2

In reference to the accepted solution in: SO:expression_evaluator Can anyone provide a version that works with negation as well? things like ((!(0 or !1) and !((0 or 1 or 1) and !1)) need to work as well. I got it working so that negating the 0's or 1's is fine but I can't get it to work with the negation of whole groups(!'s at begi...

I figured out how to write realloc, but I know the code is not right?

What I decided to do is call malloc copy the old block to the new block free the old block and return the pointer to the new block The code below is what I have so far...but I know it is not right...any help on fixing the code would be greatly appreciated... If you need more code than what I have provided I have a post previous to...

Is there any FOSS lib for reading Excel files using C

Hi As the title says, I am looking for source code that shows how to read(write) MS Excel files in pure C (OS agnostic). I have seen some Java code (e.g. JExcel) and would use that if I can't find some existing C code with similar functionality. What I need is to read an Excel file and convert it to XML (or some other more manageable f...

How do you do inheritance in a non-OO language?

I read that early C++ "compilers" actually translated the C++ code to C and used a C compiler on the backend, and that made me wonder. I've got enough technical knowledge to wrap my head around most of how that would work, but I can't figure out how to do class inheritance without having language support for it. Specifically, how do yo...

question on changing file descriptor number in c...

Hi all...my question is how would I change the program below so that it takes a file descriptor number on the command line rather than a file name? Any help would be greatly appreciated. Thank You. include "csapp.h" int main (int argc, char **argv) { struct stat stat; char *type, *readok; /* $end statcheck */ if (a...

Is array name a pointer in C?

Is an array's name a pointer in C? If not, what is the difference between an array's name and a pointer variable? ...

linking libraries -rpath LD_LIBRARY_PATH

Hello, I have some 3rd party libraries and includes (I have copied them to the this location /usr/ssd/include and /usr/ssd/lib) that I need to link with my application. I have just created a test application to see if I can link ok. However, when I try to run my app I get the following message. ./app: error while loading shared librari...