查看單個文章
舊 2011-11-22, 11:52 PM   #1
bobo0836
註冊會員
榮譽勳章

勳章總數0
UID - 347578
在線等級: 級別:0 | 在線時長:2小時 | 升級還需:3小時
註冊日期: 2011-07-12
文章: 6
精華: 0
現金: 8 金幣
資產: 8 金幣
預設 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--;                  
    }
  }
}
bobo0836 目前離線  
送花文章: 2, 收花文章: 0 篇, 收花: 0 次
回覆時引用此帖