iT邦幫忙

0

[VS Code macOS] Strlen 在 C 語言無法使用

  • 分享至 

  • twitterImage

在 VS Code 上,用 C語言使用 strlen 卻跑出底下的錯誤,看了stack overflow 也不太會解決,想請問要如何解決呢?麻煩各位回覆了!

https://ithelp.ithome.com.tw/upload/images/20210316/20135864ysFysrnRaH.png

感謝看完問題的你,以及所有幫助的大神!

圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中
0
海綿寶寶
iT邦大神 1 級 ‧ 2021-03-17 00:32:43
最佳解答

錯誤訊息有說:strnlen 要兩個參數,你只傳了一個
用法可參考這篇

Kodaiyen iT邦新手 5 級 ‧ 2021-03-17 10:51:31 檢舉

感謝你 TAT
謝謝大神救了我,自學程式語言有你們真好

0
EN
iT邦好手 1 級 ‧ 2021-03-17 00:58:34

可以善用 Linux manual page 查看定義:

size_t strnlen(const char *s, size_t maxlen);

Description
The strnlen() function returns the number of bytes in the string
pointed to by s, excluding the terminating null byte ('\0'), but
at most maxlen. In doing this, strnlen() looks only at the first
maxlen characters in the string pointed to by s and never beyond
s[maxlen-1].

如果不需要指定最大長度,使用 strlen() 即可。

Kodaiyen iT邦新手 5 級 ‧ 2021-03-17 10:53:28 檢舉

不好意思,原先就是無法使用 strlen() ,但目前解決了喔!
謝謝你的協助!

0
一級屠豬士
iT邦大師 1 級 ‧ 2021-03-17 07:54:52

在終端機裡面 使用 man 查看

man 3 strlen

https://ithelp.ithome.com.tw/upload/images/20210317/200506470FvoMbDxrP.png

Kodaiyen iT邦新手 5 級 ‧ 2021-03-17 10:54:06 檢舉

想請問要輸入哪些指令來查看呢?

man 3 strlen

Kodaiyen iT邦新手 5 級 ‧ 2021-03-18 14:09:19 檢舉

看到了!感謝你的協助!

我要發表回答

立即登入回答