-2

How can I get the length of the array 'source'? I have this so far I was wondering if anyone had any suggestions. Thank you

For size I get -2074.

I do not know the length of the array, it's a random input.

#include <ctype.h>

int StrToUpper(char *destination[],  const char *source[])
{
    int size = *(&source + 1) - source;

    return size;
}
Nemo
  • 49
  • 5
  • You can't get the size of an "array" if all you have is a pointer. The program just doesn't have any information about what a pointer might point to. – Some programmer dude Jan 16 '21 at 07:31
  • 2
    This is a copy of OP's (now deleted) [same question](https://stackoverflow.com/questions/65746396/how-to-get-the-length-of-an-array-sent-to-a-function-without-knowing-its-length), which was closed as a duplicate a few hours ago. – dxiv Jan 16 '21 at 07:34
  • yah, sorry, my other was answered, and I tried to post it but it wouldn't let me. – Nemo Jan 16 '21 at 07:37
  • Note that `char *source[]` doesn't declare `source` as a pointer to an array, it's an array of pointers (or really a pointer to a pointer or `char **source`). If you want a pointer to an array you need to use `char (*source)[]`. Which in this case doesn't make any difference. – Some programmer dude Jan 16 '21 at 07:37
  • That link helps, but I'm still really lost, because its a hw problem and we don't know what string he is gonna input – Nemo Jan 16 '21 at 07:38
  • 2
    Do you really need the *size* of the arrays? Or the *string length*? What is the use-case? What is the actual underlying problem you need to solve? – Some programmer dude Jan 16 '21 at 07:40

1 Answers1

1

You can do something like:

int StrToUpper(char *destination[],  const char *source)
{
    int size = 0;
   
    while(source[size] != '\0')
        size++;

    return size;
}

I am assuming that you will be passing string to this function like: StrToUpper("some","somemore")

David Ranieri
  • 39,972
  • 7
  • 52
  • 94
chaitanya
  • 186
  • 1
  • 1
  • 8