/*******************************************
FunctionName: delspace.c
Function: delete the space in the string
Author: jychen
CreateDate: 2008/10/23
Input: A string is contained space
Output: A string is not contained space
System: Windows
********************************************/
#include "stdio.h"
#include "string.h"
void main()
{
char *JoinStr(char *pstr1);
char *pStr1 = "h e l l o w o r l d ! ";
clrscr(); /* clear the screen of the previous print */
puts(JoinStr(pStr1));
}
char *JoinStr(char *pstr1)
{
int i, count = 0;
for (i = 0; i < strlen(pstr1); i++)
{
count = i;
if(pstr1[count] == ' ')
{
/* delete the serial space in the string */
while (pstr1[count] == ' ')
{
count++;
}
/* if this char is not space then remove to the i positon */
pstr1[i] = pstr1[count];
/* Set the space to this position because it removeforward */
pstr1[count] = ' ';
}
}
return pstr1;
}
阅读(1654) | 评论(0) | 转发(0) |