Answer the question
In order to leave comments, you need to log in
What is the best practice for simple strings in C?
Hello. I am new to C and I have one question that is difficult to find a definitive answer. At least due to the fact that I do not know all the subtleties. In C, a string is an array of characters. So what is the best practice. I have a program in which there is a lot of text, statistical and everything is clear with it. But here with dynamic lines I came to a standstill. There are about 20-30 of them, mostly they are not big. From 4 to 30-35 characters.
So here's the best way to do it. Declare each line with a pre-larger value. For example 35 characters. Or all the same dynamically allocate. The first method seems to me simpler and more reliable. But somewhere they write that this is bad practice, etc. In general, any advice on strings in C is generally interesting. Since the information in Rus. small in comparison with hype languages.
Answer the question
In order to leave comments, you need to log in
In your case, it's better (and faster) to have a static string length
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question