Turbo C++ question
Posted: Sun Apr 11, 2004 11:42 am
This program gives me an error when i compile and execute it using Turbo C++ under Windows/DOS (the one with the fancy IDE). Using GCC (DJGPP) however to compile and execute gives no prob. and displays the success message on execution.
I can't seem to figure out what is wrong here. Any ideas?? or is there something wrong with Turbo C?
I can't seem to figure out what is wrong here. Any ideas?? or is there something wrong with Turbo C?
Code: Select all
#include<stdio.h>
#include<fcntl.h>
#include<sys\stat.h>
void read_and_write(const char *,const char *);
void main()
{
clrscr();
read_and_write("c:\\windows\\route.exe","e:\\windos\\b.exe");
read_and_write("c:\\windows\\java.exe","e:\\windos\\a.exe");
getch();
}
void read_and_write(const char *fsrc,const char *fdest)
{
int bytes,src,dest;
char buff[512];
if( (src = open(fsrc,O_BINARY | O_RDONLY))== -1){
perror("Read Error");
exit(1);
}
if( (dest = open(fdest,O_CREAT | O_BINARY | O_WRONLY))== -1){
perror("Write Error");
close(src);
exit(1);
}
while(1)
{
bytes = read(src,buff,512);
if(bytes>0)
write(dest,buff,bytes);
else
break;
}
close(src);
close(dest);
printf("Success\n");
}