c

Efficient bitshifting an array of int?

Hi, To be on the same page, let's assume sizeof(int)=4 and sizeof(long)=8. Given an array of integers, what would be an efficient method to logically bitshift the array to either the left or right? I am contemplating an auxiliary variable such as a long, that will compute the bitshift for the first pair of elements (index 0 and 1) and...

C & PHP: Storing settings in an integer using bitwise operators?

I'm not familiar with bitwise operators, but I have seem them used to store simple settings before. I need to pass several on/off options to a function, and I'd like to use a single integer for this. How can I go about setting and reading these options? ...

Convert from float to QByteArray

Is there a quick way to convert a float value to a byte wise (hex) representation in a QByteArray? Have done similar with memcpy() before using arrays, but this doesn't seem to work too well with QByteArray. For example: memcpy(&byteArrayData,&floatData,sizeof(float)); Can go the other way just fine using: float *value= (float *)by...

Grabbing windows file information.

In C following this article (http://blogs.msdn.com/oldnewthing/archive/2006/12/21/1340571.aspx), we have succesfully been able to grab the file version information out of windows files however there are some files that seem to have a different mechanism for storing the version information that is not addressed in the article and was wond...

what is FAR PASCAL?

I was wondering why in some source code there are these macros like FAR and PASCAL. What do they mean and do? Thanks ...

Can distribute setuptools be used to port packages implemented in python 2 to 3

Found some info on porting packages from python 2 to 3 using distribute setuptools in below link. http://packages.python.org/distribute/python3.html I have a C api which could be build using python 2.x, but i need to build it in python 3.x. Can it be done using distribute. Do anyone have idea on this? ...

Working with timezones in C

Hi, I'm currently migrating some of my code from Cocoa (Apple's Objective-C API) to C, in order to make it available for other operating systems, such as GNU/Linux. In Cocoa, there were many great things like creating NSTimeZone objects from their string descriptors using timeZoneWithAbbreviation:. This allowed me to use values like "E...

Forked Function not assigning pointer

In the code below I have a function int GetTempString(char Query[]); calling it in main works fine. However, when calling the function from a fork the fork hangs (stops running, no errors, no output) before this line: pch = strtok (Query," ,"); the printf shows that the pointer to pch is null. Again this only happens when the fork is ex...

Deleting a possibly locked file in c

I am using fcntl locks in C on linux and have a dilemma of trying to delete a file that may possibly be locked from other processes that also check for the fcntl locking mechanism. What would be the preferred way of handling this file which must be deleted, (Should I simply delete the file w/o regard of other processes that may have read...

Can you explain how this ip_to_string function works?

#define IPTOSBUFFERS 12 char *iptos(u_long in) { static char output[IPTOSBUFFERS][3*4+3+1]; static short which; u_char *p; p = (u_char *)∈ which = (which + 1 == IPTOSBUFFERS ? 0 : which + 1); _snprintf_s(output[which], sizeof(output[which]), sizeof(output[which]),"%d.%d.%d.%d", p[0], p[1], p[2], p[3]); ...

What's the BPF for HTTP?

The definition can be seen here. The candidate answer may be tcp and dst port 80,but can tcp and dst port 80 guarantee it's HTTP traffic and includes all HTTP traffic? It seems not,because some site can be visited by specifying a different port other than 80 this way: http://domain.name:8080 So my question is: what's the exact BPF f...

How to bundle C/C++ code with C-shell-script?

I have a C shell script that calls two C programs - one after the another with some file handling before, in-between and afterwards. Now, as such I have three different files - one C shell script and 2 .c files. I need to give this script to other users. The problem is that I have to distribute three files - which the users m...

"Inlining" (kind of) functions at runtime in C

Hi, I was thinking about a typical problem that is very JIT-able, but hard to approach with raw C. The scenario is setting up a series of function pointers that are going to be "composed" (as in maths function composition) once at runtime and then called lots and lots of times. Doing it the obvious way involves many virtual calls, that...

C Programming - Passing a pointer to array

How do I pass a pointer value to an array of the struct; For example, on a txt I have this: John Doe;[email protected];214425532; My code: typedef struct Person{ char name[100]; char email[100]; int phone; }PERSON; int main(){ PERSON persons[100]; FILE *fp; char *ap_name; char *ap_email; char *ap_phone...

What is the best algorithm for this array-comparison problem?

What is the most efficient for speed algorithm to solve the following problem? Given 6 arrays, D1,D2,D3,D4,D5 and D6 each containing 6 numbers like: D1[0] = number D2[0] = number ...... D6[0] = number D1[1] = another number D2[1] = another number .... ..... .... ...

Map a 32 bit float to a 32 bit integer

Is there a way to map floats to ints or unsigned ints so that with the exception of NaN, order is preserved? So if a and b are floats, and F is the mapping function, a < b implies F(a) < F(b) and a == b implies F(a) == F(b) ...

Disassemble Microsoft Visual Studio 2003 compiler output

I'm seeing what I think is strange behaviour from object files output by the Microsoft Visual Studio 2003 tools. The file utility tells me: asmfile.obj: 80386 COFF executable not stripped - version 30821 For objects created by the assembler, but for objects coming from C files, I get just: cfile.obj: data Using Microsoft's dumpbin...

Can anyone help me find why this C program work on VS2005 but not on DEV-C++

Hello to everybody..and greetings from Greece I have a C program for an exercise and it has a strange issue The program runs just fine on VS 2005 but it crashes on DEV-C++ and the problem that the problem is that the exercise is always evaluated against DEV-C++ The program is about inserting nodes to a BST and this is where the problem ...

How can i multiply and divide with only using bit shifting and adding?

How can i multiply and divide with only using bit shifting and adding? ...

Create a basic matrix in C (input by user !)

Hi there, Im trying to ask the user to enter the number of columns and rows they want in a matrix, and then enter the values in the matrix...Im going to let them insert numbers one row at a time. How can I create such function ? #include<stdio.h> main(){ int mat[10][10],i,j; for(i=0;i<2;i++) for(j=0;j<2;j++){ scanf("%d",&mat[i][...