c

A recursive method to find depth of a any(not necessarily complete) Binary tree

I am trying to compute the depth of any(not necessarily complete) BST in O(log n) time recursively. This is the algorithm I came up with: //max() - returns the max of two numbers int depth(root) { if(root->left==NULL && root->right==NULL) //leaf return 0; else if(root->left!=NULL && root->right==NULL) //with right leaf ...

Creating a stack of strings in C

I want to have a stack that takes strings. I want to be able to push and pop strings off, as well as clear the whole stack. I think C++ has some methods for this. What about C? ...

Delete multiple nodes from a binary search tree

Hello, I have a binary search tree created in c. The problem is I can't find a efficient way to delete all the nodes with e.g. id>5. When I traverse the tree, if I delete a node, the recursion is getting error, because the structure is not the same. Is there any way, instead of using a helping stack to keep the data before delete them...

How can I open a DB handle in C and pass it to Perl using SWIG?

Please help me in writing SWIG interace. I want to open a database connection handle in C program. This handle must be passed to Perl, where I will use the Perl DB interface for interacting with the database. For security purpose we wanted to use this mechanism. I want to pass the database handle using SWIG interface. Added: We are ...

How to reset a struct entry in C

I have an array of structs. It's declared like this: tableEntry [MAXSCOPE][MAXSIZE]; When the structs are created, C automatically initializes all the members to either 0 or null. Let's say that I have given some values to the struct members of tableEntry[1][0], tableEntry[1][1], and tableEntry[1][2]. Now I want to reinitialize a...

How to add one line before the last line in C

Hi I am working in C on Unix platform. Please tell me how to append one line before the last line in C. I have used fopen in appending mode but I cant add one line before the last line. I just want to write to the second last line in the file. ...

How do C/C++/Objective-C compare with C# when it comes to using libraries?

This question is based on a previous question: http://stackoverflow.com/questions/1917935/how-does-c-compilation-get-around-needing-header-files. Confirmation that C# compilation makes use of multiple passes essentially answers my original question. Also, the answers indicated that C# uses type and method signature metadata stored in as...

how to make YY_INPUT to point to a string rather than stdout in lex & yacc (solaris)

i want my yylex to parse a string rather than a file or stdout.how can v do it in solaris ...

What could cause the dead loop, indicated by print "Dead loop on virtual device " in linux kernel?

The print comes when the 'current lock owner' of a kernel resource is current CPU. I don't know what could lead to this condition. Couldn't find much on the net. Anyone debugged this? ...

How to use something likes ***prof to find which function cost most computational complexity?

I am writing a C project. Now I just doubt one function in the whole project may be take the most of computational complexity. If I can make sure about this, I can further improve this function with a more clear target. Or, is there any tools for this usage?? I mean to find the most "expensive" function in the whole program or project??...

x64 compatible C source

I think I know what #ifdefs I need to use to be x86-32 and x86-64 compatible on both msvc and gcc, see below. Is this complete for those platforms? #if defined(_MSC_VER) # if defined(_M_IA64) || defined(_M_X64) # define SIZEOF_SIZE_T 8 # define SIZEOF_VOIDP 8 # elif defined(_M_IX86) # define SIZEOF_SIZE_T 4 # define SIZEO...

Using boolean values in C

C doesn't have any built in boolean types. What's the best way to use them in C? ...

Writing software for E-Book Reader Devices

Can you please recommend any E-Book Reader which can execute a third-party software, so that anybody can create software for such device? ...

Should a person new to windowed applications study X, GTK+, or what?

Let's say the factors for valuing a choice are the library of widgets available, the slope of the learning curve, and the degree of portability (platforms it works on). As far a language binding goes, I'm using C++. Thanks! ...

How to generate thumbnail for some pages of a PDF file?

I want a C library for generating image snapshots of PDF files. Then I would use this to generate the thumbnail of the first page. Is there a library for this? ...

[C Program] How to generate a new random number and transpose the matrix?

Thanks for all helped me before. But I still have some questions about the program. How to generate a new random number while the new random number is equal to the previous random number? Also how to transpose the matrix? #include "stdafx.h" #include "stdlib.h" #include "time.h" int _tmain(int argc, _TCHAR* argv[]) { int nu...

Size of pid_t, uid_t, gid_t on Linux

On Linux systems (either 32- or 64-bit), what is the size of pid_t, uid_t, and gid_t? ...

pointer vs handles in C (are the terms used to convey separate things?)

Recently, I read a white paper by an individual who refers to a pointer to a struct as a handle. The author was clearly someone who had written C code on the windows platform previously. Googling indicates that windows programmers interact with system components via handles. I am wondering if it is common practice for windows programm...

Best C/C++ Library to defang HTML?

I'm looking for a C/C++ functional equivalent to HTML::Defang, and my Google-fu has not been able to uncover anything. I want to keep any benign tags and strip out/defang everything else. Lacking an actual library, any pointers to complete lists of tags/attributes/etc to defang would be appreciated. I know of http://en.wikipedia.org/wiki...

How to use nan and inf in C?

I have a numerical method that could return nan or inf if there was an error, and for testing purposed I'd like to temporarily force it to return nan or inf to ensure the situation is being handled correctly. Is there a reliable, compiler-independent way to create values of nan and inf in C? After googling for about 10 minutes I've only...