#include /* Standard input/output definitions */
#include /* String function definitions */
#include /* UNIX standard function definitions */
#include /* File control definitions */
#include /* Error number definitions */
#include /* POSIX terminal control definitions */
#include
#define ENTER 10 /*ASCII code of LF in linux*/
#define MAX 10
int main(void) {
//int fd;
//fd = open("/dev/ttyS0", O_RDWR|O_NOCTTY|O_NDELAY);
int fp, fp2;
char str[MAX],ch;// buffer
int bytes=0;
fp=open("copyfile1.txt", O_RDWR);
fp2=open("output.txt", O_RDWR | O_CREAT, S_IREAD | S_IWRITE);//
if( (fp==-1) || (fp2==-1) )
{
printf("file cannot be opened, fp=%d, fp2=%d\n", fp, fp2);
return 1;
} else {
while( (bytes=read(fp, str, MAX))>0){
write(fp2, str, bytes);//
}
}
close(fp2);//
close(fp);
printf("Copying finish...\n");
return 0;
}