现在的位置: 首页 > 综合 > 正文

删除字符串中多余的空格(多个空格只留一个)

2013年02月15日 ⁄ 综合 ⁄ 共 422字 ⁄ 字号 评论关闭
#include "stdafx.h"
#include <math.h>
#include "stdio.h"
#include "conio.h"
#include "string.h"
#define LENGTH_STRING 100
#define LENGTH_LINE 100

void deblank(char string[]);

int _tmain(int argc, _TCHAR* argv[])
{
	char src[LENGTH_STRING];

	gets(src);
	deblank(src);
	puts(src);
	
	
	getch();
}

void deblank(char string[]){
	int i = 0 ;
	while((string[i]) != NULL ){
		if(string[i]== ' ' && string[i+1] == ' '){
			int ii = i;
			while(string[ii] != NULL){
				string[ii]=string[ii+1];
				ii++;
			}
		}else{
			i++;
		}
			
	}
}

抱歉!评论已关闭.