Is there a function used to calculate the length of an array. For instance, if someone enters John, the function outputs 4. Or is it necessary to write a function to do it, and how is it done. (This is not homework this time, just want to know for my job).
Slate2006
0
Newbie Poster
Recommended Answers
Jump to PostYou are asking two different questions.
To find the length of an array (the amount of storage allocated to it), you can use the sizeof( ) operator, but only in the function where the array was allocated. As in:
int arr[] = { 1, 2, 3, …
Jump to PostIf it's actually an array, there are two common ways to find the size. The first is a template that converts an array of type T to an array of type char, which can then be used as the operand to sizeof to get the number of elements:
Jump to PostThat's because
cin >> my;
skips preceding whitespace, grabs characters until it again encounters whitespace (blank, tab, newline.)
Use getline, as in:cin.getline( my, 100 );
This reads all input (including blanks and tabs) for up to size-1 characters or until newline (the default delimeter, you …
All 11 Replies
vmanes
1,165
Posting Virtuoso
Narue
5,707
Bad Cop
Team Colleague
Slate2006
0
Newbie Poster
vmanes
1,165
Posting Virtuoso
Slate2006
0
Newbie Poster
vijayan121
1,152
Posting Virtuoso
Narue
5,707
Bad Cop
Team Colleague
Calicoder
-4
Newbie Poster
Narue
commented:
It took you four years to come up with the same solution vijayan did in 2007. Grats on a pointless bump.
-4
adityatandon
23
Junior Poster in Training
zeroliken
79
Nearly a Posting Virtuoso
Sebelius
0
Newbie Poster
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.