LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 03-20-2001, 01:33 PM   #1
CropA
LQ Newbie
 
Registered: Mar 2001
Location: Tarn
Distribution: Mandrake 8
Posts: 16

Rep: Reputation: 0

I,ve got a task to create a copy program:
Task goes:
Write a copy program(copies simple text files) called mycopy. This utility should be adopted by the systems administrator and made available to users.
I,m running Redhat 5.2 and was wondering if i could do it as a script or a C prog.
Regards
CropA
 
Old 03-20-2001, 01:41 PM   #2
trickykid
LQ Guru
 
Registered: Jan 2001
Posts: 24,149

Rep: Reputation: 269Reputation: 269Reputation: 269
I am not a programmer, but if they can make adduser scripts to add users to the system, I see why not to use just a script instead of C in general.
 
Old 03-20-2001, 10:27 PM   #3
crabboy
Senior Member
 
Registered: Feb 2001
Location: Atlanta, GA
Distribution: Slackware
Posts: 1,821

Rep: Reputation: 121Reputation: 121
Red face

Here is a simple copy I just wrote in C. It will copy text files and binary files as well. This is copy in its most basic form. This program does not display any error messages if any of the file operations should fail.

Gary

Here it goes: copy.c

#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>

#define BUFFER_SIZE 1000
main(int argc, char * argv[] )
{
int fdIn = 0;
int fdOut = 0;
int iReadSize = 0;
int iWriteSize = 0;
char szBuffer[ BUFFER_SIZE + 1 ];

if ( argc != 3 )
printf("Usage: copy src dest\n");

fdIn = open( argv[1], O_RDONLY );
fdOut = creat( argv[2], S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH );

while ( (iReadSize = read( fdIn, szBuffer, BUFFER_SIZE )) > 0 )
{
iWriteSize = write( fdOut, szBuffer, iReadSize );

} // end while

close( fdIn );
close( fdOut );
}
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
How can we copy the program code wriiten in notepad to linux vi editor? mayank027 Linux - General 2 10-25-2005 06:14 AM
Copy program not working skie_knite007 Programming 4 08-28-2005 02:13 PM
Looking for a program that will copy BDG CDs Tux_Phoenix Linux - Software 0 02-03-2005 10:51 PM
Exercise 1-9. Write a program to copy its input to its output, replacing each string zombi3 Programming 3 12-21-2003 02:28 AM
boot error after using Copy Commander to copy debian system onto larger new drive Interceptor Linux - Hardware 7 05-04-2003 12:40 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 04:56 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration