Chinaunix首页 | 论坛 | 博客
  • 博客访问: 209638
  • 博文数量: 136
  • 博客积分: 2919
  • 博客等级: 少校
  • 技术积分: 1299
  • 用 户 组: 普通用户
  • 注册时间: 2011-03-11 09:08
文章分类

全部博文(136)

文章存档

2013年(1)

2011年(135)

我的朋友

分类: C/C++

2011-03-16 14:16:36

#include    "stdio.h"


void squeeze(char s[], int c);

/* main: removes all occurrences of the character c from a string  s*/

int main()
{
    char c;
//    char str[];
    char    str[] = "This is a c programs ";
    printf ("The original string is: %s\n", str);
    while ((c = getchar()) != EOF)
      squeeze(str, c);
    printf("Now thw string is: %s\n", str);

    return 0;
}

/* squeeze: delete all c from s */
void squeeze(char s[], int c)
{
    int i, j;

    for (i = j = 0; s[i] !='\0'; i++)
      if (s[i] != c)
        s[j++] = s[i];
    s[j] = '\0';
}
阅读(294) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~