W
wdh3rd
Hi everyone. I'm new to C and I have a few questions:
I am making files for permutations and combinations. Files to be made
are perm.c, perm.h, combo.c, and combo.h.
Since both combinations and permutations use factorial to solve their
problems, factorial is supposed to be in both perm.c and combo.c, and
declared private.
(1) You wouldn't ever put a prototype in a header if that function was
only in one file...right? So, any function unique to perm.c, e.g.----
int permr(int n, int r) ---- should be a prototype in its file only(in
perm.c, not in combo.c), and not the header.
(2) The only prototype that makes sense to put in the header is
factorial ---- int factorial(n) --- since it's used by both perm.c and
combo.c....Is this a problem since factorial (per instructions) is
supposed to be declared private?? I'm declaring it private by making
it static. Is it kosher to put prototypes of private methods in
headers??
(3) I've seen in at least one place where <stdio.h> is in both the
header and the source file. This is okay, right?? I'm assuming that
without every file having the <stdio.h>, there'd be no way to read the
header, so it's needed there, and the header needs it to output it's
stuff. Is that a correct reading...that it's okay to have <stdio.h> in
the header and source??
(4) When trying to do an exponential, using pow(n,r), I get a warning
that I'm converting to 'int' from 'double' even though I'm only using
ints and multiplying them. How can I multiply two ints and make that a
double??
Many thanks for any help anyone can give me.
I am making files for permutations and combinations. Files to be made
are perm.c, perm.h, combo.c, and combo.h.
Since both combinations and permutations use factorial to solve their
problems, factorial is supposed to be in both perm.c and combo.c, and
declared private.
(1) You wouldn't ever put a prototype in a header if that function was
only in one file...right? So, any function unique to perm.c, e.g.----
int permr(int n, int r) ---- should be a prototype in its file only(in
perm.c, not in combo.c), and not the header.
(2) The only prototype that makes sense to put in the header is
factorial ---- int factorial(n) --- since it's used by both perm.c and
combo.c....Is this a problem since factorial (per instructions) is
supposed to be declared private?? I'm declaring it private by making
it static. Is it kosher to put prototypes of private methods in
headers??
(3) I've seen in at least one place where <stdio.h> is in both the
header and the source file. This is okay, right?? I'm assuming that
without every file having the <stdio.h>, there'd be no way to read the
header, so it's needed there, and the header needs it to output it's
stuff. Is that a correct reading...that it's okay to have <stdio.h> in
the header and source??
(4) When trying to do an exponential, using pow(n,r), I get a warning
that I'm converting to 'int' from 'double' even though I'm only using
ints and multiplying them. How can I multiply two ints and make that a
double??
Many thanks for any help anyone can give me.