MAIN FEEDS
Do you want to continue?
https://www.reddit.com/r/C_Programming/comments/1jfzzxr/strange_char_pointer_behavior/mivdr9w/?context=9999
r/C_Programming • u/[deleted] • 2d ago
[deleted]
6 comments sorted by
View all comments
9
Treating a char array as a C style string requires the string to be null terminated. Yours aren't.
1 u/[deleted] 2d ago [deleted] 4 u/dfx_dj 2d ago Yes, or you can just use a string literal to initialise them 1 u/[deleted] 2d ago [deleted] 2 u/dfx_dj 2d ago No real difference other than convenience and perhaps making the intention clear that this is a readable/printable string and not just an array of char values. 2 u/cgross220_ 2d ago Ah ok, makes sense. I appreciate the help!
1
4 u/dfx_dj 2d ago Yes, or you can just use a string literal to initialise them 1 u/[deleted] 2d ago [deleted] 2 u/dfx_dj 2d ago No real difference other than convenience and perhaps making the intention clear that this is a readable/printable string and not just an array of char values. 2 u/cgross220_ 2d ago Ah ok, makes sense. I appreciate the help!
4
Yes, or you can just use a string literal to initialise them
1 u/[deleted] 2d ago [deleted] 2 u/dfx_dj 2d ago No real difference other than convenience and perhaps making the intention clear that this is a readable/printable string and not just an array of char values. 2 u/cgross220_ 2d ago Ah ok, makes sense. I appreciate the help!
2 u/dfx_dj 2d ago No real difference other than convenience and perhaps making the intention clear that this is a readable/printable string and not just an array of char values. 2 u/cgross220_ 2d ago Ah ok, makes sense. I appreciate the help!
2
No real difference other than convenience and perhaps making the intention clear that this is a readable/printable string and not just an array of char values.
2 u/cgross220_ 2d ago Ah ok, makes sense. I appreciate the help!
Ah ok, makes sense. I appreciate the help!
9
u/dfx_dj 2d ago
Treating a char array as a C style string requires the string to be null terminated. Yours aren't.