Write a program in C that takes two command line arguments T
Write a program in C that takes two command line arguments. The first is the filename for an NFA file, and the second is the filename of a strings file. Your program will
 convert the NFA to an equivalent DFA and determine whether each string in the strings file is in
 the language of the NFA or not.
The NFA file has the following contents:
 The first line identifies the number of states (N) from 0 to N-1
  The second line identifies the alphabet as a string of lowercase letters in no particular
 order, without spaces between the letters. Epsilon isn\'t identified here but is essentially
 a member of the alphabet.
  The third line identifies the initial state
  The fourth line is a list of final states by state number, in no particular order, with one
 space between each state number
 The remainder of the file contains one line for each of the N states from 0 to N-1. These
 lines indicate the destination states for transitions on alphabet members with the last
 entry for epsilon transitions. Each set of target states per alphabet member is a
 no-whitespace, comma-delimited list of states by number. -1 indicates no transition on
 the character.
The strings file contains one string per line to be tested against the given NFA. A line with only the string \"E\" is the same as the empty string. Your program should determine whether each string is accepted by the NFA by print \"good\" or \"fail\" followed by a space character and the string tested.
Solution
A command-line argument is the information that follows the program\'s name on the command kine of the operating system.
Command-line arguments are used to pass information to the program.
Many programs allow command-line arugements to be specified wthen they are run.
For exaple, when you use a text editor, you probably specify the name o the file you want to edit after the name of the word processing program.
Example: if you use a word processor called WP, the this line causes the file TEST to be edited.
WP TEST
Here, test is a command-line argument, c programs may also utilise command-line aruguments . these are passsed to a c program through two arguments to the main() function. The parameters are called argc and argv. These paramenters are optional and are not used when no command-line argumentsare being used.
The argc parameter holds the number of arguments on the command-line .
The argv parameter is an array of string pointers.
All command-line arguments are passed to main() as strings.
Program displays all the command-line arguments.
#include<stdio.h>
void main(int argc, char*argv[])
{
int i;
for(i-1;i<argc;i++)
printf(\"%s\", argv[i]);
}
void main(int argc, char*argv[])
{
if(argc!=2)
{
printf(\"Specify a password\");
exit(1);
}
if(!strcmp(argv[1], \"password\"))
printf(\"Access Permitted\");
else
{
printf(\"Access denied\");
exit(1);
}
}
This program only allows access to its code if the correct password is entered aa a command-line argument.
Program on two command-line arguments:
#include<stdio.h>
#include<stdlib.h>
void main(int argc, char*argv[])
{
FILE *fp /*file pointer*/
char ch;
if(argc!=3)
{
printf(\"Usage:find $$$ filename ch\ \");
exit(1);
}
if((fp=fopen(argv[1], \"r\"))=NULL)
{
printf(\"cannot open file\ \");
exit(1);
}
while((ch=get(fp))!=EOF)
if(ch==*argv[2])
{
printf(\"%c found\", ch);
break;
}
fclose(fp);
}
DFA implementation:



