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 |
N人帮着看看,strstr函数能用不?#include <stdio.h> #include <stdlib.h> #include <string.h> int SafeStrCpy2KeyWord(char * dest, char * source,int size,char* key) { if(strcmp(key,"NULL") == 0) { strcpy(source,"NULL"); return 0; } char * p=strstr(dest,key); int n=p-dest; if(n==0) { strcpy(source,dest); return 0; } strncpy(source,dest,n); source[n]='\0'; return n; } int main() { char dest[256],key[256],source[256]; while(scanf("%s",dest)!=EOF) { int size=strlen(dest); scanf("%s",key); while(strcmp(key,"END")!=0) { int len=SafeStrCpy2KeyWord(dest,source,size,key); printf("%d %s\n",len,source); scanf("%s",key); } } return 0; } Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator