int fact_rec(int n)
{
printf("%d\n",n);
if(n==1) return n;
else return fact_rec(--n)*n;
//else return n*fact_rec(--n); gives same result
//correct output comes for n*fact(n-1)
}
In the above recursive implementation of the factorial function,
fact_rec(5) returns 24. Whereas, if I use
n*fact_rec(n-1)
in place of
n*fa...
I know that is better to use Python to call Posix and Win API, but I would like to know if there is a not so painful way to call C APIs from Groovy, or at least with Java.
...
With a pthread_cond_t we have to associate a mutex, When signalling the condition I've seen code such as
pthread_mutex_lock(&mutex);
//code that makes condition true
pthread_cond_broadcast(&cond);
pthread_mutex_unlock(&mutex);
and
pthread_mutex_lock(&mutex);
//code that makes condition true
pthread_mutex_unlock(&mutex);
pthread_...
Possible Duplicate:
Best Algorithm for Bit Reversal ( from MSB->LSB to LSB->MSB) in C
Hi All,
I had just written down a bit reversal function and its shown below.I feel its lengthy.So is there any faster and short method or any other alternative which you feel is much more faster and better.
Assuming integer is 4 byte...
I want my PHP extension to declare a class equivalent to the following PHP:
class MyClass
{
public $MyMemberArray;
__construct()
{
$this->MyMemberArray = array();
}
}
I'm following the examples in "Advanced PHP Programming" and "Extending and Embedding PHP" and I'm able to declare a class that has integer prop...
I'm working on a file format that should be written and read in several different operating systems and computers. Some of those computers should be x86 machines, others x86-64. Some other processors may exist, but I'm not concerned about them yet.
This file format should contain several numbers that would be read like this:
struct Lon...
Hi,
I am trying to figure out how to grab the start directory for my program. I am using C and have access to GLib. On the Linux side it is easy, g_get_current_directory as soon as the program is launched, and store this value for later use. I tried using the same method on windows but g_get_current_directory returns whatever %APPDATA% ...
What is the most commonly used (simplest) C / C++ compiler used on Windows when using the NetBeans IDE (6.7)?
I want to write (mostly) simple C programs. I have Cygwin installed but for some reason NetBeans doesn't like it. I'm getting a error from it and before I try to figure this out, I thought I should find and (if needed) configur...
I'm aware that in C it's best practice to never cast the return value of malloc(). I've read that the compiler assumes that malloc() returns an int if you don't include stdlib.h. Of course it would produce an error if you tried to implicitly assign an int to something that's not an int, but that error could be covered up by an explicit c...
How can I pass an array of struct by reference ?
example :
struct Coordinate {
int X;
int Y;
};
SomeMethod(Coordinate *Coordinates[]){
//Do Something with the array
}
int main(){
Coordinate Coordinates[10];
SomeMethod(&Coordinates);
}
...
Does blocking mode put that particular task in a "Process Wait" state, as i think non-blocking sockets needs a "busy-wait" or "spin-lock" implementation, explicitly from the user. Or blocking mode sockets are nothing but implicit-implementations of busy-wait by the kernel.
In locking mechanisms like semaphores/mutexes/monitors a lock is...
This is in extension to my previous question
http://stackoverflow.com/questions/1107391/how-does-blocking-mode-in-unix-linux-sockets-works
What i gather from Internet now, all the process invoking blocking calls, are put to sleep until the scheduler finds the reasons to unblock it. The reasons can vary from buffer empty to buffer full ...
Who in the kernel is responsible for killing a process.
What if a "kill" comes, and the process is in the blocked state. Does the kill waits until the process comes to running state to clean himself.
If someone can answer more in terms of kernel, like when a SIGINT from the kill command is generated, what all is invoked by the kernel...
Is their a way in C to diferentiate between Vista and XP.
Reason being is the the path I use is different in both.
...
I have been having a problem identifying a flash drive in my code.
Luckily my code can be run from the flash drive. So is there a way in C (or C++) to tell what drive letter (or drive name) a program is running on?
Reason I need to know is when I plug the USB drive in, it is running a program that copies files from the computer to the ...
this is the first time i m trying random numbers with c (i miss c#) here is my code
int i , j= 0;
for(i=0;i<=10;i++){
j = rand();
printf("j = %d\n",j);
}
with this code i get the same sequance everytime the code but it generates random sequences if i add srand(/*somevalue/*) before the for loop . can someone explain why ?
...
How to make a simple C program which will produce keyboard key hits.
if ( condition ) {
KeyPress('A');
}
I am working on Ubuntu 8.10 Linux OS
...
The C language was used to write UNIX to achieve portability -- the same C language program compiled using different compilers produces different machine instructions. How come Windows OS is able to run on both Intel and AMD processors?
...
Hi,
I want to access variable v1 & v2 in Func() while being in main()
int main(void)
{
Func();
int k = ? //How to access variable 'v1' which is in Func()
int j = ? //How to access variable 'v2' which is in Func()
}
void Func()
{
int v1 = 10;
int v2 = 20;
}
I have heard that we can access from Stack. But how to do....
For :
int *a;
a is an address where an integer can be stored.
&a is an address where a is stored.
Then, where is &a stored?
And, where is &(&a) stored?
And, where is &(&(&a)) stored?
Where does this storing of addresses stop?
...