length of a string

I need to calculate the length of a string and print it out in the first element of the array A[0]. I am not allowed to use any string functions or c++ built in functions for this.

I don't want the answer, I want advice on what I should do and a push to get started.

1
2
3
4
5
6
7
8
9
int stringLength(char *A)
{
 int *temp;

 //calculation

 A[0] = temp;

}
Last edited on
So...the string HAS to have some terminator, so you can tell where it stops.
How might you go through and find out how many elements there were before that terminator?
to find out how many elements there are, I would use a loop to output each letter in the string ... So that loop would give me the length of that string if I have a variable to hold how long the string is?
Sure would. Though you don't need to output each character, unless you want to print the string as well. Might as well for debugging purposes, though - that's what I always do.
How would you loop through it? What kind of loop would you use?
EDIT: go with JayhawkZombie
Last edited on
OP wanted to come to that conclusion on their own. Why give it to them like that? The point of my asking that question was to encourage OP to try to come up with that on their own.
My bad... there's still a lot to come up with, If you want I can edit my post (I think OP hasn't seen it yet)
Topic archived. No new replies allowed.