remove extra space

#include <stdio.h>
#include <iostream>
#include <fstream>
#include <string>
#include <stdlib.h>
using namespace std;

char * removeMultipleSpaces(char * str)
{
    int i,j = 0;
    bool in = false;
    for(i = 0; str[i] != '\0'; i++)
    {
        if(str[i] != ' ')
        {
            str[j++] = str[i];
            in = false;
        }
        else
        {
            if(in)
            {
                i++;
            }
            else
            {
                str[j++] = str[i];
                in = true;
            }
        }
    }
    str[j] = '\0';

    return str;
}

int main() 

    char str[] = "lsjd    lsdk   ksdj   d";
    removeMultipleSpaces(str);
    printf("%s\n",str);
    system("pause");
    return 0;
}

posted on 2012-08-26 09:28 三少_爷 阅读(131) 评论(0)  编辑 收藏 引用


只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   知识库   博问   管理


<2024年3月>
252627282912
3456789
10111213141516
17181920212223
24252627282930
31123456

导航

统计

常用链接

留言簿

随笔分类

随笔档案

My Website

搜索

最新评论

阅读排行榜

评论排行榜