标题:求救 怎么将dbf转成txt的同时在每个数据后面加逗号
取消只看楼主
qq251223577
Rank: 1
等 级:新手上路
帖 子:2
专家分:0
注 册:2008-4-11
 问题点数:0 回复次数:0 
求救 怎么将dbf转成txt的同时在每个数据后面加逗号
之前看过有将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();
}
搜索更多相关主题的帖子: dbf 逗号 txt 数据 
2008-05-08 21:48



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-213239-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.769562 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved