Guest_imported
New member
- Jan 1, 1970
- 0
Hi
I'm just starting with unix/solaris and need help with the following c program.
I nedd to write a program that copies a file, named file1, to another file, named file2(needs to be crated from the c program). I have to use the getopts command to add an option to the command line for the user of -x which means "don't overwrite the file but append if it already exists(if you try to copy the file1 more then one time), and I need to check for proper use:
"I have to include at least the following in my program:
getopt
optind
opterr
case 'x':
open
read
write
while
I have started the program but as you can see isn't much
so I'm hopping someone can help me. Thank you.
*/
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include "ourhdr.h" //error functions
#define BUFFSIZE 8192
/* specify default open mode for output file here */
int omode = O_WRONLY | O_CREAT | O_TRUNC;
int main(int argc, char *argv[])
{
int c, n, fdin, fdout; //fdin is a discriptor for read and fdout for write
char buf[BUFFSIZE];
opterr = 0;
/* don't want getopt() writing to stderr */
while ( (c = getopt(argc, argv, buf!= EOF)
{
//code goes here
}
Thank you!!!
I'm just starting with unix/solaris and need help with the following c program.
I nedd to write a program that copies a file, named file1, to another file, named file2(needs to be crated from the c program). I have to use the getopts command to add an option to the command line for the user of -x which means "don't overwrite the file but append if it already exists(if you try to copy the file1 more then one time), and I need to check for proper use:
"I have to include at least the following in my program:
getopt
optind
opterr
case 'x':
open
read
write
while
I have started the program but as you can see isn't much
so I'm hopping someone can help me. Thank you.
*/
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include "ourhdr.h" //error functions
#define BUFFSIZE 8192
/* specify default open mode for output file here */
int omode = O_WRONLY | O_CREAT | O_TRUNC;
int main(int argc, char *argv[])
{
int c, n, fdin, fdout; //fdin is a discriptor for read and fdout for write
char buf[BUFFSIZE];
opterr = 0;
/* don't want getopt() writing to stderr */
while ( (c = getopt(argc, argv, buf!= EOF)
{
//code goes here
}
Thank you!!!