Hi there....
I'm trying to become more framiliar with structured programming. I have a problem with an encryption program I'm creating.....
I'm allowing command line arguments to be passed to main(), and using getopt() to allow the dash(-) option and argument following the option...
I'm about 1/4 of the way finished, it compiles fine, but when I run it, I can not specify arguments with correct results... If you could, if it's not too much of a hasle, please compile/download attatchment....
Thanks in advance.
Here is my code so far:
Code:
#include <stdio.h>
#include <unistd.h>
FILE *in;
char usage(char *name);
char infile(char *arg1);
main(int argc, char *argv[]) {
char c;
if (argc < 4) {
usage(argv[0]);
return (1);
}
while((c = getopt(argc, argv, "i:o:k:")) != EOF) {
switch (c) {
case ('i') : infile(argv[1]);
break;
}
}
}
char usage(char *name) {
printf("Usage:\t%s -i [infile] -o [outfile] -k [key]\n", name);
return;
}
char infile(char *arg1) {
if ((in = fopen(arg1, "r")) == NULL) {
printf("There was an error opening \"%s\"\n", arg1);
exit(1);
}
}