int strlen(char *str){
int len=0;
while (str[len]!=0)
len++;
return len;
}
In other words, it counts how many characters are there from the character pointed to to the closest '\0'. It doesn't measure the actual size of the array, because that's impossible.
sizeof(temp) is giving the size of a pointer, which is, in this case, 4 bytes. sizeof calculates sizes at compile time, and the array temp points to was created at run time, so it's impossible for the compiler to know how long it is.
EDIT: In that case, if you need to represent the actual value 0, you can't use a simple char array. You'll also have to pass the size of the array around, otherwise your code will not be able to tell how long the array is.
When you have a string, it is an array of chars. You would need to read them as characters and convert them to numbers if you want to handle them that way.
I know.
@OP: The cctype library has several functions for manipulating chars and turning them into numbers, and the like. cstdlib may also have some things to look at. Check the reference if that's what you are trying to do.
Edit your posts instead of double posting. It's just cleaner.
And I also directed you to cctype. One of those two has the atoi function to take an ascii char and convert to integer. And please capitalize. We start sentences with capital letters in English.