史萊姆論壇

史萊姆論壇 (http://forum.slime.com.tw/)
-   程式語言討論區 (http://forum.slime.com.tw/f76.html)
-   -   C語言 字串去除 (http://forum.slime.com.tw/thread268244.html)

bobo0836 2011-11-22 11:52 PM

C語言 字串去除
 
各位大大好,以下是字串去除程式碼,請問函式exclude內程式碼每行均是什麼意思?它變數是怎麼帶的?怎麼覺得書上,跟理解的有差距?請問有沒有大大肯好心解釋呢?!謝謝!!!
語法:

/* 字串去除程式 */
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
void exclude(char*,char*);
int main(void)
{
  char str1[] = "what a wonderful world!";
  char str2[] = "wonderful";  //要去除的文字
  exclude(str1,str2);
  puts(str1);
  system("pause");
  return 0;
}
void exclude(char *s1,char *s2)
{
  int i, s2_len = strlen(s2);
  for(i=0; i<(int)strlen(s1) - s2_len; i++){
    if(!strncmp(s1+i, s2, s2_len)){
      strcpy(s1+i, s1+i+s2_len);
      i--;                 
    }
  }
}



所有時間均為台北時間。現在的時間是 04:22 AM

Powered by vBulletin® 版本 3.6.8
版權所有 ©2000 - 2025, Jelsoft Enterprises Ltd.

『服務條款』

* 有問題不知道該怎麼解決嗎?請聯絡本站的系統管理員 *


SEO by vBSEO 3.6.1