Compile multiple C files with make

The links posted are all good. For you particular case you can try this. Essentially all Makefiles follow this pattern. Everything else is shortcuts and macros. program: main.o dbAdapter.o gcc -o program main.o dbAdapter.o main.o: main.c dbAdapter.h gcc -c main.c dbAdapter.o dbAdapter.c dbAdapter.h gcc -c dbAdapter.c The key thing here is that the Makefile looks … Read more

Fast n choose k mod p for large n?

So, here is how you can solve your problem. Of course you know the formula: comb(n,k) = n!/(k!*(n-k)!) = (n*(n-1)*…(n-k+1))/k! (See http://en.wikipedia.org/wiki/Binomial_coefficient#Computing_the_value_of_binomial_coefficients) You know how to compute the numerator: long long res = 1; for (long long i = n; i > n- k; –i) { res = (res * i) % p; } Now, … Read more

How can I create C header files [closed]

Open your favorite text editor Create a new file named whatever.h Put your function prototypes in it DONE. Example whatever.h #ifndef WHATEVER_H_INCLUDED #define WHATEVER_H_INCLUDED int f(int a); #endif Note: include guards (preprocessor commands) added thanks to luke. They avoid including the same header file twice in the same compilation. Another possibility (also mentioned on the … Read more

tech