」工欲善其事,必先利其器。「—孔子《論語.錄靈公》
首頁 > 程式設計 > 擠壓以從字串中刪除字元。

擠壓以從字串中刪除字元。

發佈於2024-08-01
瀏覽:819

squeeze to remove chars from string.

https://www.learntosolveit.com/ 是一個使用現代工具使用 K&R 書籍學習 C 程式設計的配套網站。這篇文章討論了書中的練習和主題。

/**
 * Exercise 2.4
 *
 * Let us write a version of squeeze(s1,s2) that deletes each
 * character in the string 1 that matches any character in the string s2.
 * Utilize user defined function mgetline to input the strings.
 * Don't use any standard library string manipulation function.
 *
 **/

#include 

#define MAXLINE 1000

int mgetline(char s[], int lim);

void squeeze(char s1[], const char s2[]);

int main(void) {
    char s1[MAXLINE], s2[MAXLINE];
    mgetline(s1, MAXLINE);
    mgetline(s2, MAXLINE);

    squeeze(s1, s2);

    printf("\n%s\n", s1);

    return 0;
}

int mgetline(char s[], int lim) {
    int i, c;

    for (i = 0; i 



遵循這篇文章中該程序的直觀解釋 - https://www.learntosolveit.com/cprogramming/chapter2/ex_2.4_squeezess

版本聲明 本文轉載於:https://dev.to/orsenthil/squeeze-to-remove-chars-from-string-4n01如有侵犯,請聯絡[email protected]刪除
最新教學 更多>

免責聲明: 提供的所有資源部分來自互聯網,如果有侵犯您的版權或其他權益,請說明詳細緣由並提供版權或權益證明然後發到郵箱:[email protected] 我們會在第一時間內為您處理。

Copyright© 2022 湘ICP备2022001581号-3