设计一个c语言程序:输入一个带有空格的字符串,比如i love you要求删除字符串中的所有空格显示

[复制链接]
查看11 | 回复5 | 2013-6-7 15:43:43 | 显示全部楼层 |阅读模式
#include int main(void){char str[80] = {0};
/*定义一个字符串*/
char *p, *q;
/*定义两个字符指针*/ printf("Please input a string: "); gets(str);
/*用scanf("%s",str)会遇到空格就断开了*/printf("str = %s\n", str); p = str;
/*指针p指向字符串str*/ whil...
回复

使用道具 举报

千问 | 2013-6-7 15:43:43 | 显示全部楼层
#include void main(){char string[100];\\*定义字符串数组 int i;printf("请输入要处理的字符串:");
gets(string);
for(i=0;string!='\0';i++)\\**for循环语句并非函数,所以我用了 {if(strin...
回复

使用道具 举报

千问 | 2013-6-7 15:43:43 | 显示全部楼层
把输入的字符串既作为源又作为目标,设立int型变量i为源下标记数,j为目标下标记数;由源向目标按字符依次拷贝,当目标接收到空格时下标变量j停止增量,最后目标收到'\0'后结束。举例如下://#include "stdafx.h"//If the vc++6.0, with this line.#include "stdio.h"int main(void)...
回复

使用道具 举报

千问 | 2013-6-7 15:43:43 | 显示全部楼层
#includeint main(void){char str[80];/*定义一个字符串*/int i,j;/*两个临时变量,计数用*/gets(str);/*用scanf("%s",str)会遇到空格就断开了*/for(i=0;str!='\0';i++)/*判断,不是字串结束符就继续*/i...
回复

使用道具 举报

千问 | 2013-6-7 15:43:43 | 显示全部楼层
#include #include int main(){int i,j,len;char a[1000];gets(a);len=strlen(a);for(i=0;i<len;i++){ if(a!=' ') putchar(a);}putchar('\n');}首发,请采纳...
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

主题

0

回帖

4882万

积分

论坛元老

Rank: 8Rank: 8

积分
48824836
热门排行