/**设计一个函数,传入一个字符串,功能是去掉这个字符串中的所有空格**/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
void Del_blackspace_array(char*,int);
int main()
{
char ch1[] = "Let it go ! Let it go! ";
int count;
char *p = ch1;
count = strlen(ch1);
Del_blackspace_array(p,count);
printf("%s\n",ch1);
return 0;
}
void Del_blackspace_array(char *p,int count)
{
char temp;
for(int i=0;i<count;i++)
{
if(*(p+i)!=' ')
{
continue;
}
else
{
for(int j=i;j<count;j++)
{
temp = *(p+j);
*(p+j) = *(p+j+1);
*(p+j+1) = temp;
}
}
}
}
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
void Del_blackspace_array(char*,int);
int main()
{
char ch1[] = "Let it go ! Let it go! ";
int count;
char *p = ch1;
count = strlen(ch1);
Del_blackspace_array(p,count);
printf("%s\n",ch1);
return 0;
}
void Del_blackspace_array(char *p,int count)
{
char temp;
for(int i=0;i<count;i++)
{
if(*(p+i)!=' ')
{
continue;
}
else
{
for(int j=i;j<count;j++)
{
temp = *(p+j);
*(p+j) = *(p+j+1);
*(p+j+1) = temp;
}
}
}
}
本文介绍了一个简单的C语言函数,该函数能够接收一个字符串作为参数,并移除字符串中的所有空格字符。通过两个循环实现这一功能:外层循环用于遍历字符串中的每个字符,内层循环则负责将空格后的字符向前移动以覆盖空格位置。

5667

被折叠的 条评论
为什么被折叠?



