gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-30 16:36:26 27 4
gpt4 key购买 nike

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

“函数声明不是原型(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/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com