
April 11th, 2002, 12:35 PM
|
 |
Banned ;)
|
|
Join Date: Nov 2001
Location: Woodland Hills, Los Angeles County, California, USA
|
|
1. Specify the complete pathname in the fopen function
Code:
#include <stdio.h>
....
....
FILE *in, *out;
/* To open a file in read mode */
in = fopen("/home/username/./somedir/filename", "r");
/* To open a file in write mode */
out = fopen("/home/username/./somedir/filename2", "w");
/* To open a file in append mode */
out = fopen("/home/username/./somedir/filename2", "a");
/* To open a file in read/write mode */
in = fopen("/home/username/./somedir/filename", "r+");
2. Use the system() call
Code:
#include <stdlib.h>
....
....
system("/usr/bin/xmms");
3. Declare the function as:
int main(int argc, char *argv[])
or
int main(int argc, char **argv)
argc will give you the number of arguments that are passed to the program and the argv array holds the actual arguments. argc will always be >=1 and argv[0] always holds the name of the program itself.
Code:
#include <stdio.h>
int main(int argc, char *argv[]) {
int x;
for (x = 0; x < argc; x++)
printf("Argument #%d is %s\n", x, argv[x]);
return 0;
}
|