英文:
According to C there is no function named strlwr(). What is wrong?
问题
#include <stdio.h>
#include <string.h>
int main(){
char n[] = "NAME";
strlwr(n);
printf("%s", n);
return 0;
}
I just wanted to print lower case "NAME" word but it doesn't work
string.c: In function ‘main’:
string.c:6:9: warning: implicit declaration of function ‘strlwr’; did you mean strlen’? [-Wimplicit-function-declaration]
6 | strlwr(n);
| ^~~~~~
| strlen
/usr/bin/ld: /tmp/cc6E8Fyf.o: in function ‘main’:
string.c:(.text+0x2f): undefined reference to ‘strlwr’
collect2: error: ld returned 1 exit status
According to C, there is no function named strlwr(), but I think there is a function named so.
英文:
#include <stdio.h>
#include <string.h>
int main(){
char n[] = "NAME";
strlwr(n);
printf("%s", n);
return 0;
}
I just wanted to print lower case "NAME" word but it doesn't work
string.c: In function ‘main’:
string.c:6:9: warning: implicit declaration of function ‘strlwr’; did you mean strlen’? [-Wimplicit-function-declaration]
6 | strlwr(n);
| ^~~~~~
| strlen
/usr/bin/ld: /tmp/cc6E8Fyf.o: in function `main':
string.c:(.text+0x2f): undefined reference to `strlwr'
collect2: error: ld returned 1 exit status
according to C there is no function named strlwr() but I think there is function named so.
答案1
得分: 2
strlwr()
在 C 标准中未定义。因此,它是否受支持取决于具体的实现。
你可以使用 ctype.h
中的 tolower()
函数来复制它的功能。
tolower()
函数的定义域是一个 int 类型的值,该值可以表示为无符号字符或 EOF 的值。如果参数具有其他值,行为是未定义的。如果 tolower()
的参数表示一个大写字母,而且存在相应的小写字母,结果将是相应的小写字母。
参考:https://stackoverflow.com/q/23618316/20017547 获取一个示例实现。
英文:
> according to C there is no function named strlwr() but I think there
> is function named so.
strlwr()
is not defined in the C standard. So it's implementation defined whether it is supported or not.
You can replicate its functionality with tolower()
(from ctype.h
).
toupper()
converts the letter c to upper case, if possible.
> The tolower() function has as a domain a type int, the value of which
> is representable as an unsigned char or the value of EOF. If the
> argument has any other value, the behavior is undefined. If the
> argument of tolower() represents an uppercase letter, and there exists
> a corresponding lowercase letter, the result shall be the corresponding lowercase letter.
See: https://stackoverflow.com/q/23618316/20017547 for a sample implementation.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论