You didn't forget.
We only steal things worth stealing.
Code:
switch (argv[optnum][2]) {
Are you sure that's what you want? Assuming all your arguments are like "-x", you'll want [1]. Remember, arrays start counting at zero.
Code:
void showusage(char* progname) {
printf(
"Usage: %s [options] file\n"
" -e = encrypt file\n"
" -d = decrypt file\n"
" -v = value to use for encryption / decryption.\n"
" default is 3.\n"
" -h = print this help page\n"
" OPTIONS ARE CASE SENSITIVE\n"
" Example:\n"
" %s -e -v 25 blah.txt\n", *progname, *progname);
}
Change your *prognames to prognames.
Code:
case 'h':
showusage(argv[0]);
break;
case 'H':
showusage(argv[0]);
break;
default:
showusage(argv[0]);
break;
You can use the fall-through behavior of switchs to your advantage:
Code:
case 'h':
case 'H':
default:
showusage(argv[0]);
(And the last case doesn't need a break.)
Code:
while (!feof(file)) {
This is not good. See the FAQ.
You open file for mode "w+", which truncuates the file, and then try to read from it. There will never be anything in it because you've just erased it.
Code:
if (fclose(file) == 0) {
return 0;
exit(0);
}
That is completely redundant. The exit(0) will never happen, so why do you have it in in the first place?
Code:
//Reminders: 0 is success, other is error.
//(I get those mixed up.....)
Evidently. You return 1 from main to indicate success, and 0 for failure.
Oh yeah, and in your switch:
Code:
switch (argv[optnum][2]) {
you don't exit if you have to print the program's usage. I think you should, otherwise it will try to open a bogus file.
decrypt() and encrypt() return ints. You store their values in chars. chars, no less, not unsigned chars or anything.