사용자:하늘/메모장/docker: 두 판 사이의 차이

(내용을 "{{삭제|}}"(으)로 바꿈)
태그: 대체됨 삭제/특정판 삭제가 요청 혹은 제안된 문서.
편집 요약 없음
1번째 줄: 1번째 줄:
{{삭제|}}
<syntaxhighlight lang="c">
#include <stdio.h>
#include <string.h>
 
void delchars (char *str, char ch)
{
    int len = strlen(str);
    int i = 0;
    while ( i < len )   
    {
        if (str[i] == ch)
        {
          int j = i, width = 0;
            if ( str[i+1] == ch)
                width = 2;
            else
                width = 1;
            while (j < len)
                str[j] = str[j+width], j++;
        }
        i++;
    }
}
int main ( )
{
    char s1[128];
    strcpy(s1, "HelloWorld");
    delchars(s1, 'l');
    printf("[%s]\n", s1); // [HeoWord]
    delchars(s1, 'W');
    printf("[%s]\n", s1); // [Heoord]
}
</syntaxhighlight>
 

2021년 10월 15일 (금) 21:51 판

#include <stdio.h>
#include <string.h>

void delchars (char *str, char ch)
{
    int len = strlen(str);
    int i = 0;
    while ( i < len )    
    {
        if (str[i] == ch)
        {
           int j = i, width = 0;
            if ( str[i+1] == ch)
                width = 2;
            else
                width = 1;
            while (j < len)
                str[j] = str[j+width], j++;
        }
        i++;
    }
}
int main ( )
{
    char s1[128];
    strcpy(s1, "HelloWorld");
    delchars(s1, 'l');
    printf("[%s]\n", s1); // [HeoWord]
    delchars(s1, 'W');
    printf("[%s]\n", s1); // [Heoord]
}