Did you bother to look at this in your other thread:
Code:
#include <stdio.h>
int main (int argc, char * argv[])
{
FILE * fp = NULL;
int c = 0;
if (argc == 2)
{
if( (fp = fopen(argv[1], "r" )) != NULL)
{
while( (c = fgetc( fp )) != EOF )
{
if( c == '<' )
{
do printf( "%c", c );
while( (c = fgetc( fp )) != EOF && c != '>' );
printf(">\n");
}
}
fclose( fp );
}
else
printf("Error opening file.\n");
}
/* remove this if you do not with to see the path to your program */
printf(argv[0]);
return 0;
}
Refer to this for more:
Code:
/*
Program:
CmdLine.c
Purpose:
Demonstrates the use of command line parameters.
argc = command line argument count
argv[number] = individual commands read
0 = the path to the current program, always a given
1 = parameter
2 = parateter
etc
*/
#include <stdio.h>
void default_message(void);
int main( int argc, char * argv[] )
{
if (argc == 2)
/* if there was a parameter besides the path to this program */
{
if(argv[1][0] == '?')
/* if the parameter was a question mark */
{
printf("Help stuff would go here.\n");
}
else
/* if the parameter was not a question mark, print whatever it was */
{
printf("%s \n", argv[1]);
}
}
else if ( argc >= 3 )
/* if there were more than 2 parameters besides the path to the program */
{
printf("Invalid input:\n");
printf("Only one command-line parameter allowed.\n");
}
else
/* if there were no paramters at all */
{
default_message();
}
return 0;
}
void default_message(void)
{
printf("CmdLine.exe:\n");
printf("The purpose of this program is to demonstrate command line arguments.\n");
printf("This program will print whatever you type on the screen.\n\n");
printf("Example:\n");
printf("C:\\>CmdLine.exe Hmmm\n");
printf("Hmmm\n");
}
Use code tags.