i played with more code for awhile and now nothing works
Code:
#include <stdio.h>
#include <string.h>
char header[2]; /* Just stores the size of the header to print. */
char title[255];
char output[255];
char input[255];
int main(int argc, char *argv[]) {
int x = 1;
int y;
int tmp;
while(argv[x] != NULL) {
for(y = 0; y <3; ++y) {
switch( get_arg(argv[x]) ) {
case 1: /* Header flag. */
strcpy(header, argv[x+1]);
tmp = check(argc, x, 2);
if(tmp != "error")
x = tmp;
else
return 1;
break;
case 2: /* Title flag. */
strcpy(title, argv[x+1]);
tmp = check(argc, x, 2);
if(tmp != "error")
x = tmp;
else
return 1;
break;
case 3: /* Output flag. */
strcpy(output, argv[x+1]);
tmp = check(argc, x, 2);
if(tmp != "error")
x = tmp;
else
return 1;
break;
case 4: /* Hopefully input file. */
strcpy(input, argv[x]);
tmp = check(argc, x, 1);
if(tmp != "error")
x = tmp;
else
return 1;
break;
}
}
printf("\nWhat args were detected\n");
printf("<header = %s>\t", header);
printf("<title = %s>\t", title);
printf("<output = %s>\t", output);
printf("<input = %s>", input);
}
return 0;
}
int get_arg(char arg[]) {
if( strcmp(arg, "-h") == 0) /* Print title as header. */
return 1;
else if( strcmp(arg, "-t") == 0) /* Change title. */
return 2;
else if( strcmp(arg, "-o") == 0) /* Change output file. */
return 3;
else /* Input file? */
return 4;
}
int check(int max, int vaule, int inc) { /* Check to see if all needed args */
if(vaule + inc < max) /* have been typed. */
vaule += inc;
else
vaule = "error";
return vaule;
}