很简单的程序,遍历输入字符串。
1、如果字符不是空格,就赋值到输出字符串中。
2、如果是空格,就跳过这个字符。
例如:
#include
#include
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
#include
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!
函数库有自带的这类函数