c

Why does this code run out of memory in java, but not in c?

In either java or c I can write a function like fun(){ fun(); } (ignoring syntax details) In java I get OutOfMemory exception but in C (and maybe some other languages) it seems to run forever, as if it were an infinite loop. Why don't I get OutOfMemory error here as well? ...

Bitstream to Float Type Coercion

I'm having trouble getting the following code to work correctly. Using an online IEEE-754 converter, I wrote out (by hand) to the testData.txt file that is read with the bit string that should signify the floating point number 75.5; the actual cout.write does show that the bit string is as I expect as well. However, when I try to coerc...

How do I use a 3rd party C library in Xcode for my iphone project?

Hello Stack Overflow, love this site and all helpful people! I'm newbie to Xcode and iPhone programming but I've pretty much got the hang of using the SDK to make programs in Obj-C (simple programs right now but make me happy). My experience is web programming (such as PHP and Perl) and I'm not really used to a lot of the new Xcode/deskt...

Why dynamic allocation (linked lists/trees), c

I get confused why you use dynamic allocation and the concept of allocating enough memory for the data. So we are covering linked lists in my class and there is this code: NODE *BuildTree(NODE *p, const char *str) { if (p == NULL) size_t length = strlen(str) + 1; p = (NODE *)malloc(sizeof(NODE)); p->string = (char *)mal...

Java Type Mapping for Java Native Access

I have a C function defined as follows: int s3vold_(void) {...} To create a Java methods with the same argument type as the native function does the void parameter map to Pointer or nothing? E.g., int s3vold(Pointer p) {...} or int s3vold() {...} The JNA docs only refer to void* ...

Fixing pointers in binary tree delete function (node with 2 children)

Hi, I'm a having a little trouble thinking how the hell do I fix the appropriate pointers when trying to delete a node from a binary tree where that node has 2 children. I understand the basic concept and I'm basically just having trouble fixing the pointers... So, basically, my delete function is mostly done and every case is already...

Unnecessary newlines using function 'printf'

When allocating Strings on the heap (with 'malloc'), and initializing them with the standard input (using 'fgets), an unnecessary newline appears between them when trying to print them (with 'printf' and %s formatting). for example: main() { char *heap1; char *heap2; heap1=malloc(10); heap2=malloc(10); fgets(heap1,1...

Detect whether the 3gb Switch is on or off programmatically

I've been trying to determine whether the 3GB switch is on or off on the system my program is running by calling GetSystemInfo() and checking lpMaximumApplicationAddress on the SYSTEM_INFO struct. No luck. I think I am doing something wrong. How do you check whether the 3GB switch is on or not on Windows in C? Code is appreciated. tha...

obtain output of command to parse in in c / MacOSX

I'm working on a Command Line app to help me on launchd tasks to know if a task is running by returning a BOOL, the problem comes when i need to do a command line and obtain the output for further parsing. i'm coding it in C/C++ so i can't use NSTask for it, any ideas on how to achieve the goal? The Command sudo launchctl list -x [job...

how do I clean up my lua state stack?

I am using the lua C-API to read in configuration data that is stored in a lua file. I've got a nice little table in the file and I've written a query C-function that parses out a specific field in the table. (yay it works!) It works by calling a few of these kinds of functions over and over: ... lua_getglobal (...); lua_pushintege...

[C - open()] How to calculate the bit flags/enum flags for oflag in open()?

I'm working on a networking assignment and we are tasked with creating a remote file access server with a protocol we were given. My difficulties come in the lack of information I can find that explains the process of calculating the bits for the oflag argument in open(). I receive a message from a client to open a file and in the messa...

Help rearranging /solving an Equation

I have the following C formula bucket = (hash - _min) * ((_capacity-1) / range()); What I need to to rearrange the equation to return the _capacity instead of bucket (I have all other variables apart from _capacity). e.g. 96 = (926234929-805306368) * (( x -1) /1249540730) 836 = (1852139639-805306368) * ((x -1) /1249540730) As you c...

Why is this C linked list program giving 'segmentation fault'?

The first function reads a file that has a bunch of 'char's and puts them in a linked list. It is not working :(. #include <stdio.h> #include <stdlib.h> struct list { char val; struct list* next; }; typedef struct list element; int lcreate(char* fname, element* list); int ldelete(element* list); int linsert(char a, char b, el...

Analysis Tools to help you in C development

I've just started learning C and I have a hard time finding bugs, memory leaks and the like. Which are good tools to assist you in finding such things? I heard of Valgrind but are there others? ...

arrays VB.NET vs c

just a sanity check please: in VB.NET: dim myarray(5) as integer gives six elements 0 to 5 but in c? int myarray[5]; gives five elements 0 to 4 ? is this correct? ...

Good linker documentation needed!

I need to write a little library, to be loaded by setting LD_PRELOAD, and which will override some functions in the standard C library but also call those functions in the standard library. Specifically, I want my shiny new library to let users provide their own resolv.conf so they can, eg, specify their default domain, or set aliases i...

How to receive multiple UDP packets in C?

I made a function to send an UDP packet to a server and to get the returned packets. When i make a single recvfrom call it works, but i need to get all potential packets from the server within the defined timeout. Here's my code: http://pastebin.be/23548 Can someone help me? Thanks. ...

How do you print a 2D array given a data access table and a 1D array of the data?

If I have a 1 dimensional array of data such as this: 1 2 3 4 5 6 7 8 9 1 and a corresponding data access table: 0 2 5 8 How would I print the 2D diagonalized array below with the zeros? 1 2 0 0 3 4 5 0 0 6 7 8 0 0 9 1 Code would be very helpful. Thanks Here is what I tried...the if statement needs tweaking: //table[] is the acc...

Understanding c++ code; what do *datatype and classname::method mean?

I am new to C++ and I am trying to understand some code. What does it mean to have a * in front of the datatype ? and why is the class Name in front of the method name CAStar::LinkChild void CAStar::LinkChild(_asNode *node, _asNode *temp) { } ...

Encoded Char buffer storage Problem in MYSQL varchar using c

I have a encoded character buffer array of size 512 in c, and a database field of varchar in mysql. Is it possible to store the encoded char buffer into varchar. I have try this but the problem which i face that it only store the limited area of buffer into database and ignore. Kindly guide me that what is the actual problem is, and how ...