69,371
社区成员
发帖
与我相关
我的任务
分享
#include<stdio.h>
#include<stdlib.h>
#include<errno.h>
#include<string.h>
#include<time.h>
#include<error.h>
#include<signal.h>
#include<sys/time.h>
#include<sys/types.h>
#include<netinet/in.h>
#include<arpa/inet.h>
#include<sys/socket.h>
#include<sys/wait.h>
#include<unistd.h>
#include<netdb.h>
typedef struct Depost
{
char szSerial[10 + 1]; /* 流水号 */
char szPhone[13 + 1]; /* 手机号码 */
char szMoney[16 + 1]; /* 金额 */
char szTime[14 + 1]; /* 交易时间 */
char szTradeFlag[1 + 1]; /* 交易状态 */
}strDepost;
char* GetItemValue(int nIndex, char *src, char *split)
{
int n, i ;
char *pIndex ;
char *p ;
char tempbuff[64];
if (nIndex < 0 || src == NULL)
return NULL;
for (pIndex = src, i = 0; i < nIndex; i ++)
{
pIndex = strstr(pIndex, split);
if (pIndex == NULL) return NULL;
pIndex += strlen(split);
}
memset(tempbuff, 0, sizeof(tempbuff));
p = pIndex;
n = 0;
while (*p && memcmp(p, split, strlen(split)) != 0 && (n < 63))
tempbuff[n++] = *p ++;
tempbuff[n] = '\0';
return tempbuff;
}
int main(int argc,char** argv)
{
char szCrmFile[256];
strDepost strCrmDepost_s;
char szCrmLine[256];
FILE *pCrmFile;
char cmd[256];
memset(szCrmFile, 0, sizeof(szCrmFile));
sprintf(szCrmFile, "%s/crm1", getenv("FILESERVERDIR"));
/* 开始对帐,以CRM文件为参照物 */
if ((pCrmFile = fopen(szCrmFile,"r")) == NULL)
{
printf("打开CRM明细对帐文件错误\n");
return -1;
}
while(1)
{
memset(szCrmLine,0,sizeof(szCrmLine));
if (fgets(szCrmLine, sizeof(szCrmLine), pCrmFile) != NULL )
{
printf("crmLine %s\n",szCrmLine);
memset(&strCrmDepost_s, 0, sizeof(strCrmDepost_s));
printf("\nGetItemValue %s,",GetItemValue(0, szCrmLine, ","));
strcpy(strCrmDepost_s.szSerial, GetItemValue(0, szCrmLine, ","));
printf("strCrmDepost_s.szSerial %s\n",strCrmDepost_s.szSerial);
strcpy(strCrmDepost_s.szPhone, GetItemValue(1, szCrmLine, ","));
strcpy(strCrmDepost_s.szMoney, GetItemValue(2, szCrmLine, ","));
strcpy(strCrmDepost_s.szTime, GetItemValue(3, szCrmLine, ","));
strcpy(strCrmDepost_s.szTradeFlag, GetItemValue(4,szCrmLine , ","));
printf("ok\n");
}
else
{
break;
}
}
fclose(pCrmFile);
return 0;
}
sscanf(szCrmLine,"%[^,],%[^,],%[^,],%[^,],%[^,]",
strCrmDepost_s.szSerial,
strCrmDepost_s.szPhone,
strCrmDepost_s.szMoney,
strCrmDepost_s.szTime,
strCrmDepost_s.szTradeFlag
);