printf
(
"the changed string is: %s\n"
,a);
printf
(
"the blank number is: %d\n"
,count);
getchar();
return
0
;
#include <stdio.h>
#include <malloc.h>
#include <string.h>
void remove_str_blank(char *tempstr);
int main()
char *str=(char *)malloc(100);
printf("input the string: ");
scanf("%[^\n]",str);
remove_str_blank(str);
system("pause");
return 0;
void remove_str_blank(char *tempstr)
int count = 0;
int len = strlen(tempstr);
char *str2=(char *)malloc(sizeof(char)*len+1);
char *str1 = tempstr;
char *strx = str2;
while(*str1 != '\0'){
if (*str1 == ' ')
count++;
}else{
*str2 = *str1;
str2++;
str1++;
*str2 = '\0';
printf("the blank number is: %d\n",count);
printf("the changed string is: %s\n",strx);
free(strx);
类似的还有字符串的替换、删除、比较、添加等一系列字符串操作,可以参考c++标准库,里面提供了很多非常好用的函数,如:构造表示、容器、迭代器、字符访问等,以及string类的一些方法。
C/C++字符串函数
例程结果:

p1 = str; //first pointer
p2 = str; // second pointer to the remaining string
if (p1==NULL) return;
while (*p1)
if (*p1 != ' ')
去除空格
1.这个函数是js的字符串替换函数,这个函数有两个参数,第一个函数可以是字符串或正则表达式(用以进行匹配的子字符串),第二个函数是字符串(替换匹配的子字符串)。就是在原字符串上把和第一个参数相同的字符串替换成第二个参数的字符串。
2.你这个例子使用的是正则表达式匹配字符串,其中”/ /”这个是固定写法,”\s”是转移符号用以匹配任何空白字符,包括空格、制表符、换页符等等,”g”表示全...
char str[5]={'*','*','*','*','*'};
for(i=0;i<6;i++){
printf("%*s",i,"");//*是占位符由i代替指定域宽,和%2d类似。
puts(str);
return 0;
输出如下图形:
ubuntu 下解决“no java virtual machine was found after searching the following locations:” 方法