void read_txt(const char* Input, const char* Output){
FILE *fin = fopen(Input, "rb");//以二进制读入
FILE *fout = fopen(Output, "w");
unsigned char ch1,ch2;
while(fscanf(fin, "%c%c", &ch1,ch2) != EOF){//直到文件结束
fprintf(fout, "%d%d", ch1,ch2);//以10进制输出
}
}
int main(){
read_txt("D:/IN.txt","D:/OUT.txt");//txt文件目录
return 0;
}
注:判断文件结束处的语句:fscanf(fin, "%c%c", &ch1,ch2)。其中两个%c之间不能加空格,否则读到的二进制文件会不完整,比源文件少好多个字节
int []account;
for(int i=0;!feof(file_p);++i) /*file_p是文件标识符*/
{
fscanf(file_p,"%d",account[i]);
}
#include
void main( void )
{
FILE *f;
int a,b,c,d,e;
f = fopen("a.txt", "r");
while(fscanf(f,"%d %d %d %d %d",&a,&b,&c,&d,&e)==5)
{
//你的代码
}
fclose(f);
}