char *foo(char *dest, const char *src) {
size_t i;
for (i = 0; dest[i] != '\0'; i++);
Here, I'm iterating to get the size of dest. In this case I’d input "hello " into dest, which is a size of 6. When I try to use sizeof(dest) I get 4 as the returned value. I want to be able to get the size of the content that's inside of dest without using this for loop.
char *foo(char *dest, const char *src) {
while (*dest != '\0') dest++; /* increment the length of dest's pointer*/
EDIT:: i'd like to take a moment to show that i was able to get around finding the length directly.
This is all part of a strcat program. The requirement was to not use [ ] brackets to access or move around in memory.
char *strcat(char *dest, const char *src) {
while (*dest != '\0') dest++; /* increment the length of dest's pointer*/
while (*src != '\0') /* we will be incrementing up through src*/
*dest++ = *src++; /* while this is happening we are appending
* letter by letter onto the variable dest
*/
*(dest++) = ' '; /* increment up one in memory and add a space */
*(dest++) = '\0'; /* increment up one in memory and add a null
* termination at the end of our variable dest
*/
return dest; /* return the final output */
}