64,682
社区成员
发帖
与我相关
我的任务
分享
// gKeyParse.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include <stdio.h>
#include <iostream>
#include <stdlib.h>
#include <assert.h>
#include <iostream>
using namespace std;
int gKeyParse(char *buf,char *key,char *value)
{
int ret=0;
do
{
if(!buf||!key||!value)
{
ret=-1;
break;
}
char *p=NULL;
if(!(p=strstr(buf,key)))
{
ret=-2;
break;
}
p=p+strlen(key);
while(*p==0x20||*p==':'||*p=='=')
{
p++;
}
while(*p!=0x20&&*p!='\r'&&*p!='\n'&&(value+1))
{
*value++=*p++;
}
*value='\0';
}while(0);
return ret;
}
int _tmain(int argc, _TCHAR* argv[])
{
char buf[100]="This is a key : hello !";
char value[2];
char key[20]="This is a key";
memset(value,0,sizeof(value));
int ret=gKeyParse(buf,key,value);
printf("%s\n",value);
//cout<<value<<endl;
getchar();
return ret;
}
while(*p!=0x20&&*p!='\r'&&*p!='\n'&&(value+1))