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 М.
НЫСАНА КОНЦЕРТ 2024
2:26:34
Нысана театры
Рет қаралды 1,4 МЛН
小宇宙竟然尿裤子!#小丑#家庭#搞笑
00:26
家庭搞笑日记
Рет қаралды 12 МЛН
World’s Largest Jello Pool
01:00
Mark Rober
Рет қаралды 105 МЛН
44-Curso C++ (98-11-14-17) - Memset
9:54
Jonathan Reyes
Рет қаралды 889
String In Char Array VS. Pointer To String Literal | C Programming Tutorial
9:58
#22  C String Functions | C Programming For Beginners
9:40
Programiz
Рет қаралды 76 М.
C++ switch structure
5:26
Heidi Gentry Kolen
Рет қаралды 36 М.
Read And Write An Array Of Structs To A Binary File | C Programming Example
18:27
strstr implementation
7:36
Sankar Srivatsa
Рет қаралды 13 М.
struct Basics | C Programming Tutorial
24:44
Portfolio Courses
Рет қаралды 134 М.
WHY IS THE STACK SO FAST?
13:46
Core Dumped
Рет қаралды 144 М.
you will never ask about pointers again after watching this video
8:03
Low Level Learning
Рет қаралды 2,1 МЛН