This is an assignment question, i had to include a dynamic array in the below program. Since i have included the dynamic char array it skips past the function call and i dont know why? Can anyone help?
I'll give you a hint, when passing a regular char array/C string into a function you can't use strlen to find out it's length. That information is lost when the array devolves to a pointer.
You should figure out in main how big the actual string is, and then pass that information along with the array into your function.
when passing a regular char array/C string into a function you can't use strlen to find out it's length.
If what you're interested in is the length of the string (not the length of the array) then there is no problem using strlen (assuming it's a null-terminated string).
My comment was made on a code version now changed that used a static sized C string, passed that static C string into a function and then attempted to get the string size on a devolved pointer. *BUZZ!*
Yes, it works, until one day it doesn't. Best to not rely on that.
The currently shown code from the OP has a similar error with passing the size of the array into the function, not the actual size of the C string.
I marked that previous topic as solved and was unaware I could re-open it. I am new here and am learning fast... As for the repost, the code was working fine as we had discussed but when I tried to include the function, that is when I was having problems again... I seem to be a little trigger happy in my posting so i apologize.
And honestly putting a green check-mark to a topic should be the least of your concerns. Most people, even the experienced folks here, don't bother. Everyone just does an Elvis and leaves.
Yes I have realized its too easy to just post my code in this forum when I am having problems and then it ends up just being some silly syntax error that I missed...
Nevertheless, thanks for the help George, much appreciated!
My comment was made on a code version now changed that used a static sized C string, passed that static C string into a function and then attempted to get the string size on a devolved pointer. *BUZZ!*
Yes, it works, until one day it doesn't. Best to not rely on that.
I haven't seen the original code but to me it sounds like you're saying strlen is unreliable. A "C string" implies that it is null-terminated so I don't see what could go wrong. Of course the user could accidentally pass someting that is not a "C string" but that is really the fault of the caller and no C string functions will handle that correctly, not even std::cout<<.