Hi,
I'm having some trouble with my C assignment. My assignment is based on an unix program that performs translations, deletions, uppercase, lowercase, and squeezing.
My basic problem right now is my main method. I want have an output like this to access the various options listed above.
a -u<test.txt> output.txt
-a is used to run the program in gvim
but I cannot get this output. I get a message saying: tr: invalid option --u
Here's my code for the main method:
Code:
int main(int argc, char *argv[])
{
int i;
FILE *fp;
char varchar;
char s[BUFSIZE];
if(argc > 2) /*two arguments are allowed*/
{
fprintf(stderr, "usage:%s file....\n", argv[0]);
return 1;
}
if((fp = fopen(argv[0], "w"))==0)
{
perror("fopen");
return 1;
}
for(i=0; i<argc; i++)
{
if(argv[i][0] == '-')
{
if(argv[i][1] == 'u')
upper(s);
if(argv[i][1] == 'l')
lower(s);
if(varchar == 'h')
display(s);
else
fprintf(stderr, "invalid input\n");
fprintf(stderr, "Please try 'tr -h' for help\n");
}
else
fprintf(stderr, "first argument problem\n");
}
fclose(fp);
return 0;
}