hello
tell me how to compile as well as run command line arguments.
You cannot compile or run command line arguments. What you can do is
pass command line arguments to programs designed to accept them. In C
you do this by defining main as follows:
int main(int argc, char *argv[]) { /* ... */ }
Obviously argc and argv can be any legal identifier but these two names
are practically universal for this purpose. Also argv could be written
as char **argv.
The general method is to first test argc. It could be zero or any
positive value. If it is non zero, then argv[0] to argv[argc-1] contain
the arguments, whatever they are. If argc is non-zero then argv[0] is
the program's invocation name, which may not be the same as the
executable file name of the program. argv[argc] is a null pointer.
Also let me know how to open a particular text file using command line
asgument
One simple example is:
int main(int argc, char **argv) {
FILE *fp;
if (argc > 1) {
fp = fopen(argv[1], "r");
if (fp == NULL) {
fprintf(stderr, "File: %s: open failed.\n", argv[1]);
exit(EXIT_FAILURE);
}
}
else {
fprintf(stderr, "Usage: program filename\n");
exit(EXIT_FAILURE);
}
/* ... */
}
say for example
if there are three text file pt1,pt2,pt3 and if i want to open pt1
please let me know as soon as possible
Adapt from the above method.
PS. You have a habit of starting sentences as "tell me ..." etc., which
may strike some people as rude or arrogant. You might want to be a bit
more polite and do a bit more of your own homework. At least posting
whatever you have attempted so far is better than demanding answers.