规范输入 :将输入的数据中的开头,结束的空字符去掉,并将大写字符转换成小写
2013-04-25 22:32
417 查看
/*************************************************************************** 功能:将输入的数据中的开头,结束的空字符去掉,并将大写字符转换成小写 用途:用于规范输入 ****************************************************************************/ #include<cstdio> #include<cstdlib> #include<cstring> #include<ctype.h> #include<iostream> using namespace std; /**flag==1 大写转化为小写**/ /**flag==0 小写转化为大写**/ void transfStr(char *dest,bool flag) { char *ptr; int len; ptr = dest;//将一个数组的首地址给它 while (isspace(*ptr))//这里是用来去掉开头的空格 ptr++;//只是改变了ptr的指向 len = strlen(ptr); if (ptr > dest)//比较两个数组的指向 memmove(dest, ptr, len+1);//将数据搬到了数据的开头 ptr = dest+len-1;//prt指向dest的最后 while (isspace(*ptr))//用于去掉最后的空格 ptr--; *(ptr+1) = '\0';//最后一个字符加上字符串结束符 ptr = dest;//让ptr指向数组最开头 if(flag == 1) while (*ptr!='\0')//如果没有到字符串最后 { *ptr = tolower(*ptr);//将大写字母转换成小写 ptr++; } else while (*ptr!='\0')//如果没有到字符串最后 { *ptr = toupper(*ptr);//将大写字母转换成小写 ptr++; } } void test1() { char buf[256]= " To recap, the three main objectives in the Mystery Method are: \ \nTo attract a woman \ \nTo establish comfort, trust, and connection \ \nTo structure the opportunity to be seduced "; printf("*%s*\n",buf); transfStr(buf,1); printf("*%s*\n",buf); } void test2() { char buf[256]= " To recap, the three main objectives in the Mystery Method are: \ \nTo attract a woman \ \nTo establish comfort, trust, and connection \ \nTo structure the opportunity to be seduced "; printf("*%s*\n",buf); transfStr(buf,0); printf("*%s*\n",buf); } int main() { test1(); test2(); char buf[80]; printf("input:"); fflush(stdout); fgets(buf,80,stdin); printf("*%s*\n",buf); transfStr(buf,1); printf("*%s*\n",buf); return 0; } /******************* * To recap, the three main objectives in the Mystery Method are: To attract a woman To establish comfort, trust, and connection To structure the opportunity to be seduced * *to recap, the three main objectives in the mystery method are: to attract a woman to establish comfort, trust, and connection to structure the opportunity to be seduced* * To recap, the three main objectives in the Mystery Method are: To attract a woman To establish comfort, trust, and connection To structure the opportunity to be seduced * *TO RECAP, THE THREE MAIN OBJECTIVES IN THE MYSTERY METHOD ARE: TO ATTRACT A WOMAN TO ESTABLISH COMFORT, TRUST, AND CONNECTION TO STRUCTURE THE OPPORTUNITY TO BE SEDUCED* input: to me TOMMORROW IS a big day * to me TOMMORROW IS a big day * *to me tommorrow is a big day* Process returned 0 (0x0) execution time : 23.375 s Press any key to continue. ********************/
相关文章推荐
- 将输入的数据中的开头,结束的空字符去掉,并将大写字符转换成小写
- c语言从键盘中输入一串字符串,将字符中的大写转化成小写字母,将小写字母转换成大写字母,以*号键结束
- 把输入字符的小写转换成大写并输出
- 通过输入一串字符,首先判断这些字符是否全都是数字,不是的话程序结束;如果全是数字则转换为中文的大写表示
- 编写一个程序,读取键盘输入,直到遇到@符号为止,并回显输入(数字除外),同时将大写字符转换为小写,将小写字符转换为大写(别忘了cctype函数系列)
- 汇编语言: 从键盘上输入一串字符(用回车键结束,使用10号功能调用。),将其中的小写英文 字母变换为大写英文字母,其他字符保持不变。然后将变换后的字符串显示出来。
- 输入一个字符若是大写自动转换成小写(使用条件运算符来)
- 将用户输入的小写货币形式转换为规范的大写货币形式
- 写一个方法完成如下功能,判断从文本框textbox1输入的一个字符,如果是数字则求该数字的阶乘,如果是小写字条,则转换为大写,大写字符不变,结果在文本框textbox2中显示
- python 输入一个字符,是小写转换为大写,大写转换为小写,其他字符原样输出
- 将用户输入的小写货币形式转换为规范的大写货币形式
- 第5章,5.9.5_把输入的字符大写的转换成小写,小写保持不变
- 用户输入数据,按回车结束后,将数据转换成大写,打印到控制台,若用户输入over,结束键盘录入
- 输入一个字符,判断它是否为大写字母,如果是,将它转换成小写字母;如果不是,不转换。然后输出最后得到的字符.cpp
- 【廖雪峰 python教程 课后题改编】利用map()函数,把用户输入的不规范的英文名字,变为首字母大写,其他小写的规范名字
- 将用户输入的字符串转换为可换行、替换Html编码、无危害数据库特殊字符、去掉首尾空白、的安全方便代码
- 输入一个字符串,如果第二个字符是字母(a~z ,A~Z),则将其大写变小写,小写变大写,如果不是字母则将其修改为空格,并将修改后的字符串输出。
- 小写字符转换成大写 不停的循环执行
- 生成二维码 加密解密类 TABLE转换成实体、TABLE转换成实体集合(可转换成对象和值类型) COOKIE帮助类 数据类型转换 截取字符串 根据IP获取地点 生成随机字符 UNIX时间转换为DATETIME\DATETIME转换为UNIXTIME 是否包含中文 生成秘钥方式之一 计算某一年 某一周 的起始时间和结束时间
- ACM457现在给出了一个只包含大小写字母的字符串,不含空格和换行,要求把其中的大写换成小写,小写换成大写,然后输出互换后的字符串。输入 第一行只有一个整数m(m<=10),表示测试数据组数。