I want to have a char array and work with every letter separately. How do i check how many letters a char array has?
I thought sizeof(name)/sizeof(name[0]) would work but it doesnt. For loop where i != '\0' is the same story
you can store the length in the first location or two if you want to store it without wrapping it up in an object or having tag-alongs parameters in every function.
eg arr[0] = 3; sprintf(&arr[1], "abc"); //usually good enough, 256 max size treat [0] as unsigned
or if you need gigantic cast to a short, int, 64 bit int, whatever and use the first 2,4,8 bytes as size.
if you want to be a smart* ... c++ supports negative array index, so you can pointer to the string and back up to the size with some smoke and mirrors.
are you allowed to use strlen?
These tell you the size (capacity) of the array, i.e. how much storage space there is in the array. They do not tell you anything about the current content of the array! Specifically, they do not tell you the "length" of the string, i.e. how many non-NULL characters there are in the array before the terminating NULL character.
Also, the above code only works with an actual array, it does not work with plain char* pointers at all !!!
If you want to determine the "length" of a string, not counting the final NULL character, use strlen() function: