[問題] 改寫字串輸入
( *[1m *[m 為色碼,可以按 Ctrl+V 預覽會顯示的顏色 )
( 未必需要依照此格式,文章條理清楚即可 )
遇到的問題: (題意請描述清楚)
我想把某文字檔(例如:input.txt)的字串內容進行改寫,
並把改寫過的內容複製到另一個文字檔裡(input1.txt),
但卻發生input1.txt會有亂碼出現,也無法換行
例如:input.txt內容為
abababababab
abababababab
但input1.txt內容卻為
bcbcbcbcbcbcbcbcbcbcbcbc恄
(因為bbs上無法完全顯示錯誤的內容
另外附上圖片http://www.badongo.com/cn/pic/10160400)
希望得到的正確結果:
input1.txt的內容應該為
bcbcbcbcbcbc
bcbcbcbcbcbc
開發平台: (例: VC++ or gcc/g++ or Dev-C++, Windows or Linux)
Microsoft Visual Studio 2005
有問題的code: (請善用置底文標色功能)
#include <stdio.h>
#include <stdlib.h>
int main(void)
{
int i=0;
int filelen;
unsigned char *data;
FILE *fptr;
FILE *fptr1;
if((fptr=fopen("D:\\text\\input.txt","r+"))==NULL)
{
printf("\n檔案開啟失敗");
return 0;
}
fseek(fptr,0,SEEK_END);
filelen = ftell(fptr);
printf("%d\r\n",filelen);
fseek( fptr, 0, SEEK_SET);
data= (char *) malloc(filelen*sizeof(int));
fread( data, 1, filelen, fptr );
if((fptr1=fopen("D:\\text\\input1.txt","w+"))==NULL)
{
printf("\n檔案開啟失敗");
return 0;
}
for(i=0;i<filelen;i++)
{
data[i]=data[i]+1;
fputc(data[i],fptr1);
}
fclose(fptr);
fclose(fptr1);
}
補充說明:
想請教版上的高手,該如何修正比較好,
謝謝。
--
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 114.42.221.50
推
08/04 20:50, , 1F
08/04 20:50, 1F
→
08/04 20:50, , 2F
08/04 20:50, 2F
→
08/04 20:51, , 3F
08/04 20:51, 3F
→
08/04 20:51, , 4F
08/04 20:51, 4F
→
08/04 20:52, , 5F
08/04 20:52, 5F
→
08/04 20:52, , 6F
08/04 20:52, 6F
→
08/04 21:05, , 7F
08/04 21:05, 7F
C_and_CPP 近期熱門文章
PTT數位生活區 即時熱門文章