Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
Re:哪位过的大神把代码贴出来瞧瞧。。。In Reply To:哪位过的大神把代码贴出来瞧瞧。。。 Posted by:0911180012 at 2010-01-16 12:21:38 #include <stdio.h> #include <stdlib.h> #include <string.h> int SafeStrcpy2KeyWord(char* pDestBuffer, //拷贝的目的地地址 char* pSourceString, //拷贝的源地址 int nDestBufferSize, //拷贝的目的地缓冲区长度 char* szKeyWord) //指定关键字符串 { int len; if(strlen(szKeyWord)==0)len=strlen(pSourceString); else { char *end =strstr(pSourceString,szKeyWord); if(end==0)len=strlen(pSourceString); else len = end - pSourceString; } memset(pDestBuffer,0,nDestBufferSize); memcpy(pDestBuffer,pSourceString,len); return len; } int main() { char src[256],keyword[256],dest[256]; while(scanf("%s",src)!=EOF) { while((scanf("%s",keyword))!=EOF) { int len; if(strcmp(keyword,"END")==0)break; else if(strcmp(keyword,"NULL")==0) { len= 0; } else len= SafeStrcpy2KeyWord(dest,src,256,keyword); printf("%d ",len); if(len==0) { printf("NULL\n"); } else printf("%s\n",dest); } memset(src,0,256); } return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator