Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- inputFile = fopen("D:\input.txt", "r");
- outputFile = fopen("D:\output.txt", "w");
- if(inputFile)
- {
- //Get size of inputFile
- fseek(inputFile, 0, SEEK_END);
- inputFileLength = ftell(inputFile);
- fseek(inputFile, 0, SEEK_SET);
- //Allocate memory for inputBuffer
- inputBuffer = malloc(inputFileLength);
- if(inputBuffer)
- {
- fread (inputBuffer, 1, inputFileLength, inputFile);
- }
- fclose(inputFile);
- if(inputBuffer)
- {
- fprintf(outputFile, "%s", inputBuffer);
- }
- //Cleanup
- free(inputBuffer);
- fclose(outputFile);
- }
- int numBytesRead = 0;
- if(inputBuffer)
- {
- numBytesRead = fread (inputBuffer, 1, inputFileLength, inputFile);
- }
- fclose(inputFile);
- if(inputBuffer)
- {
- fwrite( inputBuffer, 1, numBytesRead, outputFile );
- }
- FILE *fin = fopen ("infile","rb"); // make sure you check these for NULL return
- FILE *fout = fopen ("outfile","wb");
- char buff[1000000]; // or malloc/check-null if you don't have much stack space.
- while ((count = fread (buff, 1, sizeof(buff), fin)) > 0) {
- // Check count == -1 and errno here.
- fwrite (buff, 1, count, fout); // and check return value.
- }
- fclose (fout);
- fclose (fin);
- fwrite (inputBuffer , 1 , inputFileLength , outputFile );
Add Comment
Please, Sign In to add comment