首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C++ >

关于将一个字符串中的小写字母改成大写字母

2012-09-23 
关于将一个字符串中的小写字母改为大写字母源码:C/C++ code#include stdio.hvoid big_lower(char *ops)

关于将一个字符串中的小写字母改为大写字母
源码:

C/C++ code
#include <stdio.h>void big_lower(char *ops);int main(void){    char *src =  "abcdefghIJKlmnopq";    big_lower(src);    puts(src);    return 0;}void big_lower(char *ops){    while(*ops)    {        if (*ops >= 'a' && *ops <= 'z')        {            *ops -= 32;        }        ops++;    }}


错误地方:
*ops -= 32;

我觉得由小写字母改为大写字母,只要将其ASCII码减小32即可,为什么有以下这种错误:
  把一个字符串中的字母由小写变为大写.exe 中的 0x00a0148a 处有未经处理的异常: 0xC0000005: 写入位置 0x00a0573c 时发生访问冲突(*ops -= 32;)

[解决办法]
char *src = "abcdefghIJKlmnopq";是常量指针,里面的数据不能修改
char src[] = "abcdefghIJKlmnopq";应该就可以了

热点排行