Finding the total number of elements declared in an array

If I have declared a char array, e.g., char array[50]; I want to pass this '50' to a function. For example( The blank _ spaces are to be filled by the number I want to pass):
//Header files
void getstr(char[]);
int main()
{
char name[30];
cout<<"Enter your name: ";
getstr(name);
return 0;
}
void getstr(char a[])
{
int b[_];
for(int i=0;i<_;i++)
{
cin.get(a[i]);
b[i]=a[i];
if(b[i]==13)
break;
}
}
Last edited on
Not sure what you're trying to do here. Char name(30)? This isn't an array declaration. Are you just wanting to make b the same size as a?
This was a way a had tried to prevent buffer overflow, while accepting strings.
Anyway, I am sorry. that should have been char name[30]. I want the no. of elements/memory reserved for the array.
Topic archived. No new replies allowed.