/* simple file copy in C */
#include <stdio.h>
int copy_file(const char* fname_in,const char* fname_out) {
char buf[1024*16];
int count;
FILE *fin = fopen(fname_in,"rb");
if (!fin) {
fprintf(stderr,"Failed to open source file '%s'\n\a",fname_in);
return -1;
}
FILE *fout = fopen(fname_out,"wb");
if (!fout) {
fprintf(stderr,"Failed to create destination "
"file '%s'\n\a",fname_out);
}
for (;;) {
count = fread(buf,1,sizeof(buf),fin);
if (count == 0) break;
fwrite(buf,1,count,fout);
if (count < sizeof(buf)) break;
}
fclose(fin);
fclose(fout);
return 0;
}
int main() {
return copy_file("test.c","test_out.c");
}
/Per W
On Thu, 23 Nov 2006, :: [F]usion[S]tream :: -- Gmail wrote:
> Interesting. For me, I'd just do a simple SYSTEM command to do a COPY
> and then a REName..
>
> This is of course in dev-cpp...
> > Dear all:
> >
> > I'm new to c++ and Dev-cpp, although I have some basics on C and Pascal from
> > college classes (which I don't remember) and I currently do web programming
> > (PHP/MySql).
> >
> > I'm trying to build a small app in c++ to "backup" files and folders. All it
> > does is to copy the original file(s) or folder(s) to the same location and
> > changing the copied filename to "original_name bk
> > todays_datetime.original_extension".
> >
> > For example, if I right-click the file index.php in explorer and select
> > "Backup This File" it creates a copy of the file named
> > index_bk_20061122172201.php in the same folder.
> >
> > I have already accomplished similar with a batch file and a vbs file, but it
> > opens a cmd window, vbs files don't get along well with anti-virus apps, and
> > I don't know how to add the context option to all files and folders (except
> > manually).
> >
> > This is probably simple to do in c++. My problem is: Where do I start ? :)
> > Tips, links, books, googles, would be much appreciated, or if you know an
> > app that does the job please let me know.
> >
> > TIA.
> >
> > Pedro.
> >
>
> -------------------------------------------------------------------------
> Take Surveys. Earn Cash. Influence the Future of IT
> Join SourceForge.net's Techsay panel and you'll get the chance to share your
> opinions on IT & business topics through brief surveys - and earn cash
> http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
> _______________________________________________
> Dev-cpp-users mailing list
> Dev...@li...
> TO UNSUBSCRIBE: http://www23.brinkster.com/noicys/devcpp/ub.htm
> https://lists.sourceforge.net/lists/listinfo/dev-cpp-users
>
|