标签: tolower

将C字符串转换为全部更低

我正在尝试将C-String转换为所有小写,而不使用ctype.h中的tolower.我的代码似乎不起作用:我收到运行时错误.我正在尝试做的是更改大写字母bij'a' - 'A'的ASCII值,据我所知,它应该将这些值转换为小写的值.

#include <stdio.h>
void to_lower(char* k) {
    char * temp = k;
    while(*temp != 0) {
        if(*temp > 'A' && *temp < 'Z') {
            *temp += ('a' - 'A');
        }
        temp++;
    }
}

int main() {
    char * s = "ThiS Is AN eXaMpLe";
    to_lower(s);
    printf("%s",s);
}
Run Code Online (Sandbox Code Playgroud)

c string ascii pointers tolower

0
推荐指数
1
解决办法
126
查看次数

C++ tolower/toupper char指针

你们知道为什么下面的代码在运行时崩溃了吗?

char* word;
word = new char[20];
word = "HeLlo"; 
for (auto it = word; it != NULL; it++){        
    *it = (char) tolower(*it);
Run Code Online (Sandbox Code Playgroud)

我正在尝试小写char*(字符串).我正在使用visual studio.

谢谢

c++ char-pointer toupper tolower

0
推荐指数
1
解决办法
1443
查看次数

分段在动态数组上使用tolower()时出错

我将此代码放在我的C编译器(Dev Cpp)上.

char *str = "SomeTHing";
for(int i = 0; str[i]; i++){
   str[i] = tolower(str[i]);
}
Run Code Online (Sandbox Code Playgroud)

这给出了分段错误,而如果我使用静态数组,

char str[10] = "SomeTHing";
Run Code Online (Sandbox Code Playgroud)

循环工作正常.任何人都可以告诉为什么会这样吗?

c arrays tolower

-1
推荐指数
1
解决办法
259
查看次数

为什么putchar(tolower(ch))打印掉每个角色中的两个?

这是我的代码,输出的每个字母都打印两次.它不是文本文件,它只在我插入我的putchar(tolower)语句时才会发生,但它的格式应该完全正确.这个陈述有什么问题?

#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>

#define MAX_STRING_SIZE 20
#define MAX_LIST_SIZE 50

int readFile(char *filename); /* function declaration for readFile, defined below */
void punct();

/* main function */
int main(int argc, char *argv[]) {
    if (argc < 2) {
        printf("%s: usage %s textFileName \n", argv[0], argv[0]);
        exit(1);
    }

    readFile(argv[1]);

    return 0;
}

int readFile(char *filename) {
    char ch;
    FILE *fPtr;

    fPtr = fopen(filename, "r"); /*open file filename, r is read only */
    if (!fPtr) {
        return …
Run Code Online (Sandbox Code Playgroud)

c tolower

-3
推荐指数
1
解决办法
378
查看次数

标签 统计

tolower ×4

c ×3

arrays ×1

ascii ×1

c++ ×1

char-pointer ×1

pointers ×1

string ×1

toupper ×1