当前位置: 技术问答>linux和unix
请高手帮看一个编译问题
来源: 互联网 发布时间:2016-04-12
本文导语: #include /* * * 从信息串中获取单条记录信息的字符串 */ void ZQGetValue (int key, char *read_buf, char *item_buf,int len) { int i; int reallen; int readlen; char *chr_posi; char *tmp_ch...
#include
/*
*
* 从信息串中获取单条记录信息的字符串
*/
void
ZQGetValue (int key, char *read_buf, char *item_buf,int len)
{
int i;
int reallen;
int readlen;
char *chr_posi;
char *tmp_chr_posi;
/* read_buf 的格式为 "..字段1..~..字段2..~..字段3..~ "必须如此 */
memset(item_buf,0,sizeof(item_buf));
tmp_chr_posi = read_buf;
chr_posi = read_buf;
for (i=1; i readlen ? readlen : len;
memcpy (item_buf, tmp_chr_posi, reallen );
item_buf[reallen]='';
return;
}
/*! fn void GetToken(char * buffer, char **source,char un, int len)
brief 按照指定的分隔符和长度解析上传数据
param Buffer 解析后字符串
param source 源字符串
param un 分隔符
param len 解析字符串的最大长度
*/
void GetToken(char * buffer, char **source,char un, int len)
{
int reallen;
char * e;
char * p;
p = *source;
printf("source is : %sn", p);
e = strchr(p,un);
if(e==0) //最后一个分隔符
{
reallen = len> strlen(p)? strlen(p):len;
}
else
{
reallen = len> e-p? e-p:len;
}
printf("real length is : %dn", reallen);
strncpy(buffer, p,reallen);
*source = *source + reallen +1;
buffer[reallen] = '';
printf("result is : %sn", buffer);
}
int main()
{
char * inputStr = "123423`10`1234*321123`23`1236";
char tmpStr[25];
char lastStr[25];
char divStr[7];
char qtyStr[7];
char endStr[300];
int i = 0;
char *temp;
// memset(tmpStr, '', sizeof(tmpStr));
while(1){
GetToken(tmpStr, &inputStr, '*', 25);
printf("tmpStr is : %sn", tmpStr);
temp = tmpStr; '
if(*temp == '')
break;
memcpy(lastStr, tmpStr, 6);
lastStr[6] = '`';
ZQGetValue (2, tmpStr, divStr, 6);
memcpy(lastStr+7, divStr, 6);
lastStr[14] = '`';
ZQGetValue (3, tmpStr, qtyStr, 10);
memcpy(lastStr+15, qtyStr, 10);
lastStr[25] = '*';
memcpy(endStr+i*25, lastStr, 25);
i++;
}
scanf("%d", &i);
}
/*
*
* 从信息串中获取单条记录信息的字符串
*/
void
ZQGetValue (int key, char *read_buf, char *item_buf,int len)
{
int i;
int reallen;
int readlen;
char *chr_posi;
char *tmp_chr_posi;
/* read_buf 的格式为 "..字段1..~..字段2..~..字段3..~ "必须如此 */
memset(item_buf,0,sizeof(item_buf));
tmp_chr_posi = read_buf;
chr_posi = read_buf;
for (i=1; i readlen ? readlen : len;
memcpy (item_buf, tmp_chr_posi, reallen );
item_buf[reallen]='';
return;
}
/*! fn void GetToken(char * buffer, char **source,char un, int len)
brief 按照指定的分隔符和长度解析上传数据
param Buffer 解析后字符串
param source 源字符串
param un 分隔符
param len 解析字符串的最大长度
*/
void GetToken(char * buffer, char **source,char un, int len)
{
int reallen;
char * e;
char * p;
p = *source;
printf("source is : %sn", p);
e = strchr(p,un);
if(e==0) //最后一个分隔符
{
reallen = len> strlen(p)? strlen(p):len;
}
else
{
reallen = len> e-p? e-p:len;
}
printf("real length is : %dn", reallen);
strncpy(buffer, p,reallen);
*source = *source + reallen +1;
buffer[reallen] = '';
printf("result is : %sn", buffer);
}
int main()
{
char * inputStr = "123423`10`1234*321123`23`1236";
char tmpStr[25];
char lastStr[25];
char divStr[7];
char qtyStr[7];
char endStr[300];
int i = 0;
char *temp;
// memset(tmpStr, '', sizeof(tmpStr));
while(1){
GetToken(tmpStr, &inputStr, '*', 25);
printf("tmpStr is : %sn", tmpStr);
temp = tmpStr; '
if(*temp == '')
break;
memcpy(lastStr, tmpStr, 6);
lastStr[6] = '`';
ZQGetValue (2, tmpStr, divStr, 6);
memcpy(lastStr+7, divStr, 6);
lastStr[14] = '`';
ZQGetValue (3, tmpStr, qtyStr, 10);
memcpy(lastStr+15, qtyStr, 10);
lastStr[25] = '*';
memcpy(endStr+i*25, lastStr, 25);
i++;
}
scanf("%d", &i);
}
|
少了几个头文件:
#include
#include
#include
#include