- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我在尝试理解 toupper() 函数时面临一个有趣的问题。请找到下面的代码:这里的问题是在输出中我总是缺少输入字符串的第一个字符。
请纠正我的错误。我在谷歌搜索了太多之后才发布此内容。
void UpperString()
{
char arr [10];
memset(arr, 0x00, sizeof(arr));
strcpy(arr, "abcd");
char *ptr = arr;
char *temp = ptr;
printf("Before Upper String - %s\n",ptr);
while(*ptr++ = toupper(*ptr))
{
printf("ptr - %s\n",ptr);
printf("FULL - %s\n",temp);
}
printf("After Upper String - %s\n",temp);
return;
} // UpperString()
输出
Before Upper String - abcd
ptr - bcd
FULL - Bbcd
ptr - cd
FULL - BCcd
ptr - d
FULL - BCDd
After Upper String - BCD
最佳答案
while(*ptr++ = toupper(*ptr))
这条线有问题。您倾向于在单个执行行中多次更改 ptr
的值,从而调用未定义的行为。
C99 §6.5: “2. Between the previous and next sequence point an object shall have its stored value modified at most once by the evaluation of an expression. Furthermore, the prior value shall be read only to determine the value to be stored.”
在另一行中增加。
while(*ptr= toupper(*ptr)){
// your code
...
ptr++;
}
关于c - 关于使用指针算术的 toupper(),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32551329/
使用 String.toUpper() 时尝试“格式化”不包含大写字符(例如阿拉伯语)的语言时,是否必须采取任何其他预防措施? string arabic = "مرحبا بالعالم"; str
对于以下功能 void display() { for (int i = 0; i 97 && (i+j)%2 == 0) SetConsoleTextAtt
已结束。此问题正在寻求书籍、工具、软件库等的推荐。它不满足Stack Overflow guidelines 。目前不接受答案。 我们不允许提出寻求书籍、工具、软件库等推荐的问题。您可以编辑问题,以便
这里我检查输入数组 (inputText[]) 中的每个字符是否至少与 LETTERS 数组中的一个字母匹配。但 toupper() 函数对我不起作用。我正在 Linux mint 上工作并使用 gc
我在尝试理解 toupper() 函数时面临一个有趣的问题。请找到下面的代码:这里的问题是在输出中我总是缺少输入字符串的第一个字符。 请纠正我的错误。我在谷歌搜索了太多之后才发布此内容。 void U
这个问题已经有答案了: Lowercase characters to Uppercase characters in C & writing to file (1 个回答) 已关闭 7 年前。 我正
我尝试了以下方法:*string = toupper(*string); 这仅使指针指向的字符串指针的第一个字符变为大写。我希望 *pointer 指向的所有字符指针均为大写。无论如何我可以做到这一点
我正在从服务器传递一条消息,该消息存储在一个名为 strObject 的字符串变量中。我希望将 strObject 中的字符串转换为大写。所以,我使用 ToUpper() 方法。但是,当我添加一个断点
我正在使用 substring 和 IndexOf 来定位字符串中的值,但如果下面的字符串 (strOldValue) 包含不同大小写的任何字符串,我的代码将不起作用。因此,如果 strOldValu
这个问题在这里已经有了答案: 关闭 12 年前。 Possible Duplicate: Convert a String In C++ To Upper Case 你好,我需要一个可移植的函数来将
我正在尝试将字符串转换为大写以便我可以对其进行操作,但是虽然我可以成功地操作自然大写字符串以及将小写转换为大写,但使用这种转换方法无法进行操作。 例如,如果我通过加密传递“hello”,我的加密字符串
我已经创建了一组算法,它接受一个字符串 vector 的输入,检查是否有任何字符串出现不止一次:如果是这样,从 vector 中删除所有额外出现的字符串,然后输出新的,'lighter ' 没有冗余的
我实现了 toUpper()。它并非 100% 有效。 代码: char* toUpper(char* string) { char* sv = string; while(*sv++
我很好奇 .ToUpper() 是如何工作的?是否存在某种映射,较低的 a 具有 UTF 代码 XYZ,而较高的 a 具有 UTF 代码 XYZ1? 最佳答案 是的,它正在使用 Unicode 元数据
我有一个 []byte,b,我想选择一个字节,b[pos] 并改变它大写(然后是小写) bytes 类型有一个名为 ToUpper() 的方法。如何将它用于单个字节? 在单个字节上调用 ToUpper
我在使用 toupper() 函数时遇到问题: 代码: #include #include using namespace std; int main (){ string input {
如果 ToUpper() 不存在,你会怎么写? i18n 和 L10n 的奖励积分 由此引发的好奇心:http://thedailywtf.com/Articles/The-Long-Way-toUp
我见过以下使用自定义 toupper() 函数的程序。 #include void my_toUpper(char* str, int index) { *(str + index) &=
长期潜伏者需要帮助,但我无法通过搜索找到。好吧,我在撒谎,我发现了一些东西,但它对我没有帮助。 我想做的是创建一个包含字符串的 char 数组并显示,将它们传递给一个函数,该函数将大写字母字符(应该只
我被分配重新编码 toUpper 和 toLower 函数。我是否必须在 if 语句中写出所有 26 个字母,例如: if ( char == 'a' ) return 'A'; 或者还有其他简单的方
我是一名优秀的程序员,十分优秀!