#include"string.h"
#include<stdlib.h>
#include<conio.h>
struct Data{
char name[3]
char place[7]
char degree[7]
}
void main()
{
FILE *fr
int i
struct Data m
int count = 0
struct Data man[3] = { {"01","200801","2323.5"},{"02","200802","2656.9"},{"03","200803","5652.4"}
}
if((fr = fopen("test.csv","wt+")) == NULL)
{
printf("wrong")
exit(0)
}
for (i = 0i <3++i)
{
fprintf(fr,"%s,%s,%s\n",man[i].name,man[i].place,man[i].degree)////这样输出,用逗号隔开的
}
rewind(fr)
do
{
++count
fgets(m.name,3,fr)
fseek(fr,1L,1)
fgets(m.place,7,fr)
fseek(fr,1L,1)
fgets(m.degree,7,fr)
printf("%s\t%s\t%s\n",m.name,m.place,m.degree)
fseek(fr,2L,1)
}while(count <3)
fclose(fr)
getch()
}
//随便写了一个,只能取到抛砖引玉的效果,时间有限。如果有不明白的地方再和我联系吧#define MAXCHAR 100
int main()
{
FILE *pb
int i,num = 0,j = 0
char pchar[MAXCHAR]
char **ppstr
char *pstr,*ppchar
memset(pchar, 0, 100)
pb = fopen("D:\\pb.csv","r")
if (pb == NULL)
{
printf("error!")
return
}
ppstr = (char **)malloc(5*sizeof(char *))//这个最多可以存5条数据
pstr = (char *)malloc(5*20)//最多5条数据,每个数据不超过20-1=19
for (i = 0i <5i++)
{
ppstr[i] = pstr + i*20
}
memset(pstr, 0 ,100)
fseek(pb, 0, SEEK_SET)
fread(pchar, 1, 100, pb)
ppchar = pchar
i = 0
while (*ppchar)
{
if (*ppchar == 0x2c)//csv文件中一条数据和另外一条数据之间分隔符0x2c
{
memcpy(ppstr[j], pchar+num,i - num)
j++
num = i+1
}
if (*ppchar == 0x0a)//CSV文件中的换行符
{
memcpy(ppstr[j], pchar+num,i - num)
j++
num = i+1
}
i++
ppchar++
}
for (i = 0i <ji++)
{
printf("%s\n", ppstr[i])
}
free(pstr)
free(ppstr)
return
}
c井号csv文件的读写速度快。根据查询相关公开信息显示,c井号csv文件是只要读不要文件处理,几千万行仅需10分钟,相对于其他的转换格式快了几十倍,读写速度很快。csv是逗号分隔值文件格式,可以用电脑自带的记事本或excel打开,csv其文件以纯文本形式存储表格数据。欢迎分享,转载请注明来源:内存溢出
评论列表(0条)