请用C语言编写一个函数,用来删除字符串中的所有空格,加上注释哟
展开全部
很简单的程序,遍历输入字符串。
1、如果字符不是空格,就赋值到输出字符串中。
2、如果是空格,就跳过这个字符。
例如:
#include <stdio.h>
#include <string.h>
int main()
{
const char * input = "Hello World! Welcome To Beijing!";
char output[1024];
int i, j, input_len;
input_len = strlen(input);
j = 0;
for(i = 0; i < input_len; i++)
{
if (input[i] != ' ')
{
output[j] = input[i];
j++;
}
}
output[j] = '\0';
printf("Input string is: %s\n", input);
printf("After spaces were removed: %s\n", output);
return 0;
}
具体的输出效果为:
Input string is: Hello World! Welcome To Beijing!
After spaces were removed: HelloWorld!WelcomeToBeijing!
1、如果字符不是空格,就赋值到输出字符串中。
2、如果是空格,就跳过这个字符。
例如:
#include <stdio.h>
#include <string.h>
int main()
{
const char * input = "Hello World! Welcome To Beijing!";
char output[1024];
int i, j, input_len;
input_len = strlen(input);
j = 0;
for(i = 0; i < input_len; i++)
{
if (input[i] != ' ')
{
output[j] = input[i];
j++;
}
}
output[j] = '\0';
printf("Input string is: %s\n", input);
printf("After spaces were removed: %s\n", output);
return 0;
}
具体的输出效果为:
Input string is: Hello World! Welcome To Beijing!
After spaces were removed: HelloWorld!WelcomeToBeijing!
展开全部
很简单的程序,遍历输入字符串,如果字符不是空格,就赋值到输出字符串中,如果是空格,就跳过这个字符。
#include <stdio.h>
#include <string.h>
int main()
{
const char * input = "Hello World! Welcome To Beijing!";
char output[1024];
int i, j, input_len;
input_len = strlen(input);
j = 0;
for(i = 0; i < input_len; i++)
{
if (input[i] != ' ')
{
output[j] = input[i];
j++;
}
}
output[j] = '\0';
printf("Input string is: %s\n", input);
printf("After spaces were removed: %s\n", output);
return 0;
}
具体的输出效果为:
Input string is: Hello World! Welcome To Beijing!
After spaces were removed: HelloWorld!WelcomeToBeijing!
#include <stdio.h>
#include <string.h>
int main()
{
const char * input = "Hello World! Welcome To Beijing!";
char output[1024];
int i, j, input_len;
input_len = strlen(input);
j = 0;
for(i = 0; i < input_len; i++)
{
if (input[i] != ' ')
{
output[j] = input[i];
j++;
}
}
output[j] = '\0';
printf("Input string is: %s\n", input);
printf("After spaces were removed: %s\n", output);
return 0;
}
具体的输出效果为:
Input string is: Hello World! Welcome To Beijing!
After spaces were removed: HelloWorld!WelcomeToBeijing!
本回答被提问者和网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
很简单的程序,遍历输入字符串,如果字符不是空格,就赋值到输出字符串中,如果是空格,就跳过这个字符。
#include <stdio.h>
#include <string.h>
int main()
{
const char * input = "Hello World! Welcome To Beijing!";
char output[1024];
int i, j, input_len;
input_len = strlen(input);
j = 0;
for(i = 0; i < input_len; i++)
{
if (input[i] != ' ')
{
output[j] = input[i];
j++;
}
}
output[j] = '\0';
printf("Input string is: %s\n", input);
printf("After spaces were removed: %s\n", output);
return 0;
}
具体的输出效果为:
Input string is: Hello World! Welcome To Beijing!
After spaces were removed: HelloWorld!WelcomeToBeijing!
#include <stdio.h>
#include <string.h>
int main()
{
const char * input = "Hello World! Welcome To Beijing!";
char output[1024];
int i, j, input_len;
input_len = strlen(input);
j = 0;
for(i = 0; i < input_len; i++)
{
if (input[i] != ' ')
{
output[j] = input[i];
j++;
}
}
output[j] = '\0';
printf("Input string is: %s\n", input);
printf("After spaces were removed: %s\n", output);
return 0;
}
具体的输出效果为:
Input string is: Hello World! Welcome To Beijing!
After spaces were removed: HelloWorld!WelcomeToBeijing!
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
函数库有自带的这类函数
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询