c - Strlwr 函数 - 在 xcode 9.2 中出现错误

标签 c string function

我试图将字符串从大写转换为小写以检查它是否是回文,但是我不断收到错误:

“函数声明不是原型(prototype)”

我已经添加了#include <string.h>在标题中,但它仍然不起作用。我该如何解决这个问题?

这是代码:

int main (void)
{
    char *user_string, *user_string_rev;
    
    /* the malloc function is used to make sure that enough memory is allocated for the string and that it does not overwrite memory boxes of other variables. */
    user_string= (char*)malloc(BUFF_SIZE*sizeof(char));
    user_string_rev= (char*)malloc(BUFF_SIZE*sizeof(char));
    printf("Please enter a string:");
    fgets(user_string,BUFF_SIZE, stdin); /* fgets function take the string the user inputs and stores it into user_string. */
    user_string_rev=strcpy(user_string_rev, user_string); /*the strcpy takes the string the user inputs and copies it to user_string_rev. */
    strlwr(user_string_rev);
    
    palindrome_check(user_string,user_string_rev); /*this is the palindrome function used to check if the two strings are palindromes, it intakes two arguments, the two strings and does not return anything. */
    
    return 0;
    
}

最佳答案

替换:

strlwr(user_string_rev);

这不是一个标准函数:

int i = 0;
while (user_string_rev[i])
{
    if (isalpha(user_string_rev[i]))
        user_string_rev[i] |= 32;
    ++i;
}

不要忘记在 .c 文件顶部添加 ctype header 以使用 isalpha:

#include <ctype.h>

关于c - Strlwr 函数 - 在 xcode 9.2 中出现错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48490108/

相关文章:

c++ - 在 C++ 的某些地方向字符串添加空格

r - 仅调用列名的一部分的函数参数 (ggplot)

c - 向文本文件写入 1024 字节时,文本文件变成二进制文件 (linux)

php - MATLAB 可执行文件太慢

regex - R - 使用正则表达式,在字符串中的第 n 个点之前设置位置并删除后面的内容

c# - 在 C# 中用多个 Char 分割字符串

里面有查询的 MySQL 函数

javascript - 如何使用 javascript 将任何类型的文本转换为切换大小写?

c - 最小/最大函数的无辜宏定义有什么问题?

无法与 Linux 上的 Lua 库链接