69,369
社区成员
发帖
与我相关
我的任务
分享
#include <stdio.h>
int getinfo(int num,char *buf,char *retval)
{
char *in = buf;
while(*in)
{
if(*in == '|')
{
num--;
if(0 == num)
break;
}
else
{
*retval = *in;
retval++;
in++;
}
}
}
main()
{
char a[]="02|03|04|05|06|0201|0202|";
char b[]="6605672251|6605672252|6605754283|6605672254|6605672255|6605672256|6605754287|";
char *excp_record,*cons_record;
excp_record = (char *)malloc(sizeof(a)+1);
cons_record = (char *)malloc(sizeof(b)+1);
excp_record = a;
cons_record = b;
int i;
char *temp,*type;
temp = (char *)malloc(5);
type = (char *)malloc(12);
for(i = 1; i < 15; i++)
{
memset(temp,0x00,12);
memset(type,0x00,6);
getinfo(i,excp_record,temp);
getinfo(i,cons_record,type);
printf("%s-%s\n",temp,type);
}
free(excp_record);
free(cons_record);
free(temp);
free(type);
return 0;
}
#include <stdio.h>
int getinfo(int num,char *buf,char *retval)
{
char *in = buf;
while(*in)
{
if(*in == '|')
{
num--;
if(0 == num)
{
break;
}
}
else
{
*retval = *in;
retval++;
in++;
}
}
}
main()
{
char a[]="02|03|04|05|06|0201|0202|";
char b[]="6605672251|6605672252|6605754283|6605672254|6605672255|6605672256|6605754287|";
char *excp_record,*cons_record;
excp_record = (char *)malloc(sizeof(a)+1);
cons_record = (char *)malloc(sizeof(b)+1);
excp_record = a;
cons_record = b;
int i;
char *temp,*type;
temp = (char *)malloc(5);
type = (char *)malloc(12);
for(i = 1; i < 15; i++)
{
memset(temp,0x00,12);
memset(type,0x00,6);
getinfo(i,excp_record,temp);
getinfo(i,cons_record,type);
printf("%s-%s\n",temp,type);
}
free(excp_record);
free(cons_record);
free(temp);
free(type);
system("pause");
return 0;
}
excp_record = a;
cons_record = b;
换成
strcpy(excp_record,a);
strcpy(cons_record,b);
#include <malloc.h>
#include <string.h>