根据C语言,没有名为strlwr()的函数。有什么问题?

huangapple go评论66阅读模式
英文:

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 &lt;stdio.h&gt;
#include &lt;string.h&gt;

int main(){
	char n[] = &quot;NAME&quot;;
	strlwr(n);
	printf(&quot;%s&quot;, 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&#39;:
string.c:(.text+0x2f): undefined reference to `strlwr&#39;
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.

huangapple
  • 本文由 发表于 2023年2月10日 16:00:55
  • 转载请务必保留本文链接:https://go.coder-hub.com/75408333.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定