Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Need help with my c program------------------------

Status
Not open for further replies.

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 &quot;ourhdr.h&quot; //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!!!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top