69,371
社区成员
发帖
与我相关
我的任务
分享
//将2.txt这个文件中的汉字、中文标点、数字保存在3.txt中
//比如
//2.txt文件的内容是:
//hi,大家好!我们都是中国人,123我们一起加油!@#$%hgfhgf
//谢谢您帮我解决这个问题!谢谢您!非常感谢!thank you very much!
//那么经过处理后3.txt的内容是:
//大家好!我们都是中国人,123我们一起加油!
//谢谢您帮我解决这个问题!谢谢您!非常感谢!
#include <stdio.h>
#include <stdlib.h>
FILE *fi,*fo;
int c1,c2;
void main() {
fi=fopen("2.txt","rb");
if (NULL==fi) {
printf("Can not open file 2.txt!\n");
return;
}
fo=fopen("3.txt","w");
while (1) {
c1=fgetc(fi);
if (EOF==c1) break;
if ('0'<=c1 && c1<='9' || '\r'==c1 || '\n'==c1) {
fputc(c1,fo);
continue;
}
if (0x81u<=c1 && c1<=0xFEu) {
c2=fgetc(fi);
if (EOF==c2) break;
fputc(c1,fo);
fputc(c2,fo);
continue;
}
}
fcloseall();
}
//将2.txt这个文件中的汉字、中文标点、数字保存在3.txt中
//GBK汉字内码范围(不包括A1xx~A9xx的标点符号英文字母特殊符号等)
//区码 ,位码
//81-A0 ,40-7E 80-FE
//AA-AF ,40-7E 80-A0
//B0-D6 ,40-7E 80-FE
//D7 ,40-7E 80-F9
//D8-F7 ,40-7E 80-FE
//F8-FE ,40-7E 80-A0
#include <stdio.h>
#include <stdlib.h>
FILE *fi,*fh,*fb,*fs;
int c1,c2;
void main() {
fi=fopen("2.txt","rb");
fh=fopen("hz.txt","w");
fb=fopen("bd.txt","w");
fs=fopen("sz.txt","w");
while (1) {
c1=fgetc(fi);
if (EOF==c1) break;
if ('0'<=c1 && c1<='9') {
fputc(c1,fs);
continue;
}
if (0xA1u<=c1 && c1<=0xA9u) {
c2=fgetc(fi);
if (EOF==c2) break;
fputc(c1,fb);
fputc(c2,fb);
continue;
}
if (0x81u<=c1 && c1<=0xFEu) {
c2=fgetc(fi);
if (EOF==c2) break;
fputc(c1,fh);
fputc(c2,fh);
continue;
}
}
fprintf(fh,"\n");
fprintf(fb,"\n");
fprintf(fs,"\n");
fcloseall();
system("copy hz.txt+bd.txt+sz.txt 3.txt >NUL 2>NUL");
system("del hz.txt");
system("del bd.txt");
system("del sz.txt");
}
//将2.txt这个文件中的汉字、中文标点、数字保存在3.txt中
//GBK汉字内码范围(不包括A1xx~A9xx的标点符号英文字母特殊符号等)
//区码 ,位码
//81-A0 ,40-7E 80-FE
//AA-AF ,40-7E 80-A0
//B0-D6 ,40-7E 80-FE
//D7 ,40-7E 80-F9
//D8-F7 ,40-7E 80-FE
//F8-FE ,40-7E 80-A0
#include <stdio.h>
#include <stdlib.h>
FILE *fi,*fh,*fb,fs;
int c1,c2;
void main() {
fi=fopen("2.txt","rb");
fh=fopen("hz.txt","w");
fb=fopen("bd.txt","w");
fs=fopen("sz.txt","w");
while (1) {
c1=fgetc(fi);
if (EOF==c1) break;
if ('0'<=c1 && c1<='9') {
fputc(c1,fs);
continue;
}
if (0xA1u<=c1 && c1<=0xA9u) {
c2=fgetc(fi);
if (EOF==c2) break;
fputc(c1,fb);
fputc(c2,fb);
continue;
}
if (0x81u<=c1 && c1<=0xFEu) {
c2=fgetc(fi);
if (EOF==c2) break;
fputc(c1,fh);
fputc(c2,fh);
continue;
}
}
fprintf(fh,"\n");
fprintf(fb,"\n");
fprintf(fs,"\n");
fcloseall();
system("copy hz.txt+bd.txt+sz.txt 3.txt");
}