السلام عليكم ورحمة الله وبركاته

#include "stdio.h"
#include "string.h"
void main ( int argc, char * argv[] )
{
//here argc should be 4 since we have 4 arguments
//argv is an array of strings, each string holding an argument
//argv[0] equals the filename "mbad", argv[1] equals "-a" or "-d"
//argv[2] equals the input file name, argv[3] equals the output file name
if (! ( ( argc == 4) && ( strcmp(argv[1],"-a")==0 || strcmp(argv[1],"-d")==0 ) ) )
{
//here if the user enters the command line arguments incorrectly, we print a
//help message as specified in the project pdf file
printf( "Usage %s [-h|-a|-d] [fname1 fname2]\n", argv[0]);
printf ("-a takes assembly and produces machine code, both file names must be given\n");
printf ("-d takes machine code and produces assembly, both file names must be given\n");
}
else
{
FILE * fIn = fopen ( argv[2], "r" );
FILE * fOut = fopen ( argv[3], "w" );
if ( fIn == NULL )
{
printf( "Could not open input file\n" );
}
else
{
if ( strcmp(argv[1],"-a")==0 )
{
//Convert from assembly to machine code
//...
//...
printf ("Conversion from assembly to machine code done successfully\n");
}
else // here argv[1] will be equal "-d"
{
//Convert from machine code to assembly
//...
//...
printf ("Conversion from machine code to assembly done successfully\n");
}
fclose (fIn);
fclose (fOut);
}
}
}



