可是输出时会将空格变成乱码.哪位高手过来指点下,感激不尽!
有没人帮下忙啊
经过努力终于完成了.DBF转换成.xls和.txt,谢谢各位.代码如下:各位高手有什么好建议请提下!!!
#define M 100
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <conio.h>
void main()
{
FILE *fp, *out1, *out2;
unsigned int recno, headlength, reclength;
unsigned long recnumber;
unsigned char t1, t2, t3, t4;
char fname[13], str[M], oname[13], outname[13];
int i;
printf("请输入要转换的\n");
printf("文件名(.dbf):\n");
gets(fname);
printf("输出文件(.txt):\n");
gets(oname);
printf("输出文件(.xls):\n");
gets(outname);
if(strchr(fname, 0x2e) == NULL)
{
strcat(fname, ".dbf");
}
if(strchr(oname, 0x2e) == NULL)
{
strcat(oname, ".txt");
}
if(strchr(outname, 0x2e) == NULL)
{
strcat(outname, ".xls");
}
if((fp = fopen(fname, "rb+")) == NULL)
{
printf("文件不存在%s\n", fname);
getch();
exit(0);
}
if((out1 = fopen(outname, "wb+")) == NULL)
{
printf("不能打开文件%s\n", outname);
getch();
exit(0);
}
if((out2 = fopen(oname, "wb+")) ==NULL)
{
printf("不能打开文件%s\n", oname);
getch();
exit(0);
}
while(! feof(fp))
{
fputc(fgetc(fp), out1);
}
if (fputc(fgetc(fp), out1) != EOF)
{
printf("转换xls成功\n");
}
fseek(fp, 4L, 0);
fscanf(fp, "%c%c%c%c", &t1, &t2, &t3, &t4);
recnumber = t1 + t2*0x100 + t3*0x10000 + t4*0x1000000;
fseek(fp, 8L, 0);
fscanf(fp, "%c%c", &t1, &t2);
headlength = t1 + t2*0x100;
fseek(fp, 10L, 0);
fscanf(fp, "%c%c", &t1, &t2);
reclength = t1 + t2*0x100;
fseek(fp, headlength, 0);
for(recno = 1; recno <= recnumber; recno++)
{
fgets(str, reclength+1, fp);
fputs(str, out2);
}
if (fputs(str, out2) != EOF)
{
printf("转换txt成功\n");
}
fclose(fp);
fclose(out1);
fclose(out2);
getch();
}