returning arrays?
-
can some one tell me please how do you write the return type of a function that would return an array of characters? thanks in advance!
-
can some one tell me please how do you write the return type of a function that would return an array of characters? thanks in advance!
I am assuming you want a standard "c" style array. In that case, your function prototype should look like this: char* SomeFunction();
-
I am assuming you want a standard "c" style array. In that case, your function prototype should look like this: char* SomeFunction();
Matt Gullett wrote: char* SomeFunction(); :suss: I'm not so sure. How would he know the number of elements? Unless the array is zero-terminated, but then he would call it a string and not an array of characters. I vote pro drink :beer:
-
Matt Gullett wrote: char* SomeFunction(); :suss: I'm not so sure. How would he know the number of elements? Unless the array is zero-terminated, but then he would call it a string and not an array of characters. I vote pro drink :beer:
You are correct, he asked for an "array of characters" and I assumed he wanted a string. To return an array with no predefined terminators or size, you could do one of several things. 1. Create a custom class to deal with it. 2. Instead of using a return value, use function parameters void SomeFunction(char** pszValue, int& iLen); This would be good if the function needed to determine the length and allocate the memory. OR void SomeFunction(char* pszValue, int iMaxLen); This would be good if the function just needed a pre-exising array of max size. 3. Use a byte array and use the first N bytes to specify the length. I am sure there are many other ways to do this also. Matt Gullett
-
You are correct, he asked for an "array of characters" and I assumed he wanted a string. To return an array with no predefined terminators or size, you could do one of several things. 1. Create a custom class to deal with it. 2. Instead of using a return value, use function parameters void SomeFunction(char** pszValue, int& iLen); This would be good if the function needed to determine the length and allocate the memory. OR void SomeFunction(char* pszValue, int iMaxLen); This would be good if the function just needed a pre-exising array of max size. 3. Use a byte array and use the first N bytes to specify the length. I am sure there are many other ways to do this also. Matt Gullett
I guess technically speaking there is a difference. PASCAL strings i think have a runlength encoding byte at index zero. I've always considered them to be synonymous while using Visuall C++. your bad is my bad brutha!:) "An expert is someone who has made all the mistakes in thier field" - Niels Bohr