I'm trying to create program that takes argument form the command line. e.g as below..k.out of course, is my command name..and the arguments follows..
k.out A+ B C D E
This should then print out : Pass: 3 Real:4 Highest: A+
char* pass[] = {"A+", "A", "B","B-", "C+","C"};
char* fail[] = {"D","F"};
p is the number of arguments in pass[]
Real is p plus number of arguments in fail[]
Highest is the argument in pass[] with smallest index or if none,
the argument with smallest index in fail[] or " " if no valid arguments.
Here's what i've been able to do..and i got stuck..any advise or directions would be highly appreciated..
Code:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main(int argc, char *argv[])
{
char* passing [] = {"A+", "A", "A-", "B+", "B", "B-", "C+", "C", "C-"};
char* failing [] = {"D", "F"};
int n =0;
int pCount = 0;
int fCount = 0;
for (i = 1, i<argc; i++)
{
if ( strcmp(argv[i], passing[] ==0) )
pCount++;
passing[]++;
if (strcmp(argv[i], failing[] == 0) )
fCount++;
failing[]++;
}
printf("Valid:%d, Passed:%d, Highest: %s\n", n, p, h);
}