1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60
|
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
using namespace std;
int main()
{
FILE *fp1, *fp2;
int i, j;
char path1[256], path2[256];
unsigned char buffer[1000000];
unsigned long fileLen;
strcpy(path1,"Y:\\input.txt");
strcpy(path2,"Y:\\result.txt");
if((fp1=fopen(path1, "rb")) == NULL)
{
printf("Could not open the file No. 1!\n");
return false;
}
if((fp2=fopen(path2, "wb")) == NULL)
{
printf("Could not open the file No. 2!\n");
return false;
}
fseek(fp1, 0, SEEK_END);
fileLen=ftell(fp1);
fseek(fp1, 0, SEEK_SET);
fread(buffer, fileLen, 1, fp1);
j = 0;
for(i = 0;i < (int) fileLen; i++)
{
if(buffer[i] == 0x0D)
{
//buffer[i] = 0x0D;
//fwrite(&buffer[i], sizeof(buffer[i]), 1, fp2);
buffer[i] = 0x0A;
fwrite(&buffer[i], sizeof(buffer[i]), 1, fp2);
j++;
}
else
fwrite(&buffer[i], sizeof(buffer[i]), 1, fp2);
}
printf("Number of changes: %d\n",j);
fclose(fp1);
fclose(fp2);
return true;
}
|