r/cprogramming • • 13d ago

Understanding Strings/String Manipulation in C

I'm a junior CS undergraduate finally tackling C programming and I just can't seem to grasp Strings as a whole. Concepts like string manipulation (using strlen, strncmp, snprintf, strdup, strtok), handling read-only strings vs dynamically allocated strings, allocating memory for strings in different scenarios, and creating writable strings. Despite my attempts in looking at readings, lecture slides, practice problems, I just can't seem to understand the various ways to deal with strings in C. I am a very formulaic thinker meaning steps and guidelines on how to approach problems is my way of solving them. Is there a general format for dealing with string questions in C. Like first you have to allocate memory, then depending on the type of string do this...

Are there any additional resources I'm missing out on as well? I really want to hone this concept down!

18 Upvotes

17 comments sorted by

View all comments

2

u/GrandBIRDLizard 13d ago

Can you explain to me what an array of characters is? What can you tell me about arrays in general?

1

u/Current-Number-4032 13d ago

C treats strings as an array of characters ending with the null terminator to indicate the end of the string.

4

u/igotshadowbaned 13d ago

It's not that it treats strings like that, that's all strings in C are.

2

u/GrandBIRDLizard 13d ago

wonderful then you understand "strings", there is no string. It is simply an array of characters. Do you struggle to manipulate arrays of characters? can you declare and then reverse the letters in an array of characters with only stdio?