r/C_Programming • u/UnViandanteSperduto • Oct 07 '26
Question Help me with strok function
I need to split my string but if it is of char* type the functions strtok() doesn’t work returning me a segmentation fault. I understood that C is used to lock the memory of the string in Read-Only “mode” when I use char*. Does it means that is immutable that data? However, I need to use the char* type because I pass that in a function (and I don’t like to use the syntax of arrays in C, I always use pointers).
10
Upvotes
View all comments
Show parent comment
3
u/ekipan85 Oct 07 '26
The language is actually explicit that you can't modify a string literal's underlying array. Freely available C23 draft N3220, in section 6.4.5 paragraph 7:
Though I usually refer to cppreference, which says the same.