Okay I've been trying to figure this out but without much luck. I'm trying to write a simple program that takes input and manipulates it. Easy and that is already done (I'm using C).
The problem is I don't want any hard coded limits on the length of the string in the program and all of the string functions seem to require an array of chars which is also fine. But I can't find a function which will just count the number of characters in a string and put the result into an int which I can then use to specify the size of the array of chars.
The only other way I can think of doing it would be to use getch() to get the characters one by one and then just have a simple counter while I am running a while loop or something. The problem is I still need to declare an array for getch to work which then adds a hardcoded limit to the length of the string my program will handle. Likewise strnlen() counts the length of a given string but it will only count it from an already existing buffer.
Should I be looking at malloc style functions for this?
The problem is I don't want any hard coded limits on the length of the string in the program and all of the string functions seem to require an array of chars which is also fine. But I can't find a function which will just count the number of characters in a string and put the result into an int which I can then use to specify the size of the array of chars.
The only other way I can think of doing it would be to use getch() to get the characters one by one and then just have a simple counter while I am running a while loop or something. The problem is I still need to declare an array for getch to work which then adds a hardcoded limit to the length of the string my program will handle. Likewise strnlen() counts the length of a given string but it will only count it from an already existing buffer.
Should I be looking at malloc style functions for this?