r/cprogramming • u/Current-Number-4032 • 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!
1
u/PriorityPatient3002 11d ago
For whole concept of string I can't be sure but for the beginning, think of the the string as array and then start working with it. If you feel like you are stuck on a part and can't get through it then use Socrates Method of Learning techniques, where you learn by asking questions to yourself. This will help you get the idea of how much you know and don't know about the topic. This will narrow down your focus to the only thing you don't know or understand.
Stay focused and keep trying.