#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
}
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)