- 论坛徽章:
- 0
|
#include <sys/types.h>;
#include <sys/stat.h>;
#include <unistd.h>;
#include <fcntl.h>;
#include <stdio.h>;
#include <errno.h>;
#include <string.h>;
#define ARGUC 8
size_t readfile_aline(int fd,char buf[],const size_t charlen);
int getIcpInfo(char icp[][],const int count,char *buf);
/*typedef struct icp_info
{
char billkind[4];
char c_icpid[6];
char c_operateid[9];
char vc_name[65];
}icpinfo;*/
int main(int argc,char *argv[])
{
int fd,rec_count,i;
/*size_t count;*/
char icpinfo[ARGUC][65];
char buf[512];
if (argc!=2)
{
printf("parameter error!\n" ;
return -1;
}
if((fd=open(argv[1],O_RDONLY))==-1)
{
printf("Open file Error\n Error No=%d\n",errno);
return -1;
}
while((long)readfile_aline(fd,buf,sizeof(buf))>;0L)
{
printf("the buf is:%s\n",buf);
if(getIcpInfo(icpinfo,ARGUC,buf)!=-1)
/*split the icpinfo string read from the datafile*/
{
if(strcmp(icpinfo[0],"gaa" ==0)
rec_count=8;
else if(strcmp(icpinfo[0],"gic" ==0)
rec_count=7;
else
continue;
for(i=0;i<rec_count;i++)
printf("record #%i is:%s\n",icpinfo);
}
}
close(fd);
}
此处省略函数readfile_aline的实现;
int getIcpInfo(char icp[][],const int count,char *buf)
{
char *pdest;
int result,idx=0,i;
char c='|';
while((pdest=strchr(buf,c))!=NULL)
{
result=pdest-buf;
if(idx<=count)
{
for(i=0;i<result;i++)
strncpy(icp[idx],buf,result);
}
else
return -1;
idx++;
buf=buf+result+1;
}
if(idx<=count)
{
i=0;
while(*(buf+i))
{
strcpy(icp[idx],buf);
i++;
}
}
else
return -1;
return 0;/* no error!*/
}
编译信息:
fileread.c: In function `getIcpInfo':
fileread.c:112: arithmetic on pointer to an incomplete type
fileread.c:124: arithmetic on pointer to an incomplete type
调试运行信息:
Program terminated with signal SIGSEGV, Segmentation fault. |
|