當前位置:編程學習大全網 - 網站源碼 - 編寫壹取某字符串子串的函數char*substr(char*s,int starloc,int len),其中s為

編寫壹取某字符串子串的函數char*substr(char*s,int starloc,int len),其中s為

#include<stdio.h>

#include<stdlib.h>

#include<string.h>

char*substr(char*s,int starloc,int len)

{char *p,*p1,*p2;

p2=p=(char*)malloc(len+1);

p1=s+starloc;

for(;*p1&&p1<s+starloc+len;)

*p++=*p1++;

*p='\0';

return p2;

}

int main()

{char *p,s[]="12345678";

p=substr(s,0,4);

printf("s=%s\ns1=%s\n",s,p);

free(p);

return 0;

}

  • 上一篇:asp.net 如何發送帶圖片的Email?
  • 下一篇:3360鼠標源代碼
  • copyright 2024編程學習大全網