strnlen() String Length Function (POSIX) | C Programming Tutorial

  Рет қаралды 1,847

Portfolio Courses

Portfolio Courses

Жыл бұрын

How to use the strnlen() string length function in C, which is not part of the C standard but available in the POSIX C library and is safer than using the standard strlen() function. Source code: github.com/portfoliocourses/c.... Check out www.portfoliocourses.com to build a portfolio that will impress employers!

Пікірлер: 10
@fifaham
@fifaham Жыл бұрын
For embedded designers: Some microcontrollers do not support similar functions and the heap memory operations, becuase the memory size of most microcontrollers do not have the huge memory size operated on by heap memory library functions. For example the maloc() is not supported in many of the 8 bits MCUs, and many other functions that deal with large memory size. However, we can initiate a string with the pointer variable and allocate to it a size that is appropriate to the MCU type, such as char serialInput[80].
@PortfolioCourses
@PortfolioCourses Жыл бұрын
Thank you for sharing this! :-)
@fifaham
@fifaham Жыл бұрын
strnlen() is very helpful but my IDE does not have it and generated error: ":0:: error: (499) undefined symbol" with size_t num = strnlen(text1,2); , however I can use strlen() without problem. I am using MPLab X IDE with X8 compiler V5.5 from microchip, if I dont find the proper library I will create my own small function to generate the same output of strnlen(). That was good info, thanks Kevin.
@PortfolioCourses
@PortfolioCourses Жыл бұрын
You're welcome! :-)
@thenightwolf224
@thenightwolf224 Жыл бұрын
We Waiting For More Content in C libcurl Library
@PortfolioCourses
@PortfolioCourses Жыл бұрын
Oh yeah? That's good to know. :-) I wanted to see how well the existing videos are viewed first, libcurl is a bit of a niche topic.
@FritsvanDoorn
@FritsvanDoorn Жыл бұрын
Okay, I am a bit far fetched, but the length should be 4 as the last charater should be '\0'. And when the strnlen function is not available it is easy to write one. A good exercise.
@PortfolioCourses
@PortfolioCourses Жыл бұрын
I don't know why they decided the length of a string does not include the null terminator. :-) I'd assume it's because the null terminator is not part of the 'content' of the string.
@fifaham
@fifaham Жыл бұрын
en.wikipedia.org/wiki/C_POSIX_library
@PortfolioCourses
@PortfolioCourses Жыл бұрын
Yes that is the POSIX library. :-)
Dangling Pointers | C Programming Tutorial
11:08
Portfolio Courses
Рет қаралды 3,1 М.
Викторина от МАМЫ 🆘 | WICSUR #shorts
00:58
Бискас
Рет қаралды 4,8 МЛН
Ouch.. 🤕
00:30
Celine & Michiel
Рет қаралды 23 МЛН
Calculate String Length Using Recursion | C Programming Example
7:55
Portfolio Courses
Рет қаралды 5 М.
Read CSV File Data Into An Array Of Structs | C Programming Example
11:05
Portfolio Courses
Рет қаралды 41 М.
Introduction To Threads (pthreads) | C Programming Tutorial
13:39
Portfolio Courses
Рет қаралды 89 М.
How do computers read code?
12:01
Frame of Essence
Рет қаралды 3,1 МЛН
lofi hip hop radio 📚 - beats to relax/study to
Lofi Girl
Рет қаралды 13 М.
strtok() function | C Programming Tutorial
12:36
Portfolio Courses
Рет қаралды 59 М.
WHY IS THE STACK SO FAST?
13:46
Core Dumped
Рет қаралды 144 М.
Why You Shouldn't Nest Your Code
8:30
CodeAesthetic
Рет қаралды 2,6 МЛН
strstr implementation
7:36
Sankar Srivatsa
Рет қаралды 13 М.