|
[Date Prev] [Date Next] [Thread Prev] [Thread Next] [Date Index] [Thread Index]
|
Re: [PLUG] this code crashes [OT]
|
| #define MAX_BUF 1024
| cout << "src:" << src << ", " << "dst:" << dst<< "\n";
| char buffer[MAX_BUF+1];
|
| size_t bytes_read;
| FILE *source, *dest;
|
| source = fopen(src, "r");
| dest = fopen(dst, "w");
| memset(buffer, 0, MAX_BUF);
|
| bytes_read = fread(buffer, 1, MAX_BUF, source);
|
| while(bytes_read)
| {
| fwrite(buffer, 1, bytes_read, dest);
| bytes_read = fread(buffer, 1, MAX_BUF, source);
| }
|
| fclose(dest);
| return 0;
1) you're feeding your C compiler invalid C. almost looks like C++.
2) you did not check that the fopens actually succeed.
3) you did not close src
4) you did not tell us the results of running the debugger.
--jeff
______________________________________________________________________
Philadelphia Linux Users Group - http://www.phillylinux.org
Announcements-http://lists.phillylinux.org/mail/listinfo/plug-announce
General Discussion - http://lists.phillylinux.org/mail/listinfo/plug
|
|