#include<stdio.h>
enum FONT{JT,FT,EN} ;
enum SIO{MO,OO,PO} ;
struct PTC_INI
{
char name[9];
char custid[5];
char itemcode[18] ;
long quaty1;
long quaty;
int b2s[9];
int ptc[4][9];
enum COLORS cortab[20];
enum FONT zt;
enum SIO zero[4];
}setint;
void save_ini(char *fname);
int main(int argc, char *argv[])
{
FILE *fp1;
if (argc<3){
clrscr();
printf("\n*************use methoed**************");
printf("bin2txt file1 file2\n");
return 1;
}
if((fp1=fopen(argv[1],"rb"))==NULL){
printf("Can't open: %s\n",argv[1]);
return 1;
}
printf("%s\n",argv[1]);
if(fread(&setint,sizeof(struct setcanshu_ini),1,fp1)!=1){
printf("Read the %s file Error!",argv[1]);
fclose(fp1);
}
printf("%ld",setint.b2s[2]);
save_ini(argv[2]);
fclose(fp1);
}
void save_ini(char *fname)
{
int i,j;
FILE *fp;
printf("%s\n",fname);
if ((fp=fopen(fname,"wb"))==NULL)
{
return;
}
fprintf(fp,"料 号:%s\t",setint.name);
fprintf(fp,"客户编号:%s\t",setint.custid);
fprintf(fp,"客户货号:s\n",setint.itemcode);
fprintf(fp,"设定产量:%ld\t",setint.quaty1);
fprintf(fp,"实际产量:%ld\n\n",setint.quaty);
fprintf(fp,"****************以下为表2参数*******************\n");
fprintf(fp,"生产速度\t实际生产速度\tT1\n");
fprintf(fp,"%d\t",setint.b2s[0]);
fprintf(fp,"%d\t",setint.b2s[1]);
fprintf(fp,"%d\t",setint.b2s[5]);
fprintf(fp,"\n");
fprintf(fp,"探针\t失败次数\tT2\n");
fprintf(fp,"%d\t",setint.b2s[2]);
fprintf(fp,"%d\t",setint.b2s[3]);
fprintf(fp,"%d\t",setint.b2s[6]);
fprintf(fp,"异长\tT4\tT3\n");
fprintf(fp,"%d\t",setint.b2s[4]);
fprintf(fp,"%d\t",setint.b2s[8]);
fprintf(fp,"%d\t",setint.b2s[7]);
fprintf(fp,"\n\n");
fprintf(fp,"****************以下为各轴设置参数***************\n");
fprintf(fp,"\t\t凸轮X\t送线Y\t三轴Z\t四轴A");
fprintf(fp,"\n");
fprintf(fp,"齿 轮 比 \t");
for(i=0;i<4;i++)
fprintf(fp,"%d\t",setint.ptc[i][0]);
fprintf(fp,"\n");
fprintf(fp,"线 周 长 \t");
for(i=0;i<4;i++)
fprintf(fp,"%d\t",setint.ptc[i][1]);
fprintf(fp,"\n");
fprintf(fp,"最高速度(转/分)\t");
for(i=0;i<4;i++)
fprintf(fp,"%d\t",setint.ptc[i][2]);
fprintf(fp,"\n");
fprintf(fp,"脉冲/转 \t");
for(i=0;i<4;i++)
fprintf(fp,"%d\t",setint.ptc[i][3]);
fprintf(fp,"\n");
fprintf(fp,"转向许可 \t");
for(i=0;i<4;i++)
fprintf(fp,"%d\t",setint.ptc[i][4]);
fprintf(fp,"\n");
fprintf(fp,"禁用许可 \t");
for(i=0;i<4;i++)
fprintf(fp,"%d\t",setint.ptc[i][5]);
fprintf(fp,"\n");
fprintf(fp,"时间 \t");
for(i=0;i<4;i++)
fprintf(fp,"%d\t",setint.ptc[i][6]);
fprintf(fp,"\n\n");
fprintf(fp,"*********************颜色**********************\n");
fprintf(fp,"\tN\t针\t延\t时\t开\t始\t速\t度\t结\t束\t序\t送\t线\t秒\t序\t三轴Z\t秒\t序\t四轴A\t秒\t序\n");
fprintf(fp,"颜色号: ");
for(i=0;i<20;i++)
fprintf(fp,"%d\t",setint.cortab[i]);
fprintf(fp,"\n\n");
fprintf(fp,"字体:%d(简体:0 繁体:1)",setint.zt);
fprintf(fp,"\n\n");
fprintf(fp,"*********************归零方式**********************\n");
fprintf(fp,"\t凸轮轴\t送线轴Y\t三轴Z\t四轴A\n");
fprintf(fp,"\t");
for(i=0;i<4;i++)
fprintf(fp,"%d\t",setint.zero[i]);
fclose(fp);
}
spint.ini是一个已经存在的文件,因此文件是以二进制流写入的,不便于阅读,所以我将此文件读入一结构体变量后再以文本流方式写入txt文件.
但当我打开此txt文件后发现所有数据均写在一行里,程序中的'\n'没起作用,如下图所示:
不知何固?
[此贴子已经被作者于2006-7-20 21:10:06编辑过]