Please use CODE tags when you post source code. If you had then I could refer to line numbers in your source code.
nameptr points to successive characters within the string. You don't want to stop when the pointer value is NULL; you want to stop when the character being pointed to is null.
Notice that NULL is different from null!
- NULL is a value that can be assigned to any pointer. Programs typically use this special pointer value to mean that the pointer variable doesn't point at anything.
- Null (or null) is a character whose value is '\0'. By definition, all well-formed strings are terminated by null.
To look at the thing being pointed at by a pointer variable you have to
dereference the pointer. This is accomplished by the unary asterisk (*) operator.
For example, your first printf statement in the loop uses the %c format string (print a single character) on the nameptr variable. You want to print the character being pointed at, not the pointer value itself. For example:
Consider a bank with many safety deposit boxes in its vault. Each box has a unique number; and that same number is stamped on the corresponding key. The box number corresponds to a pointer value. The stuff inside the box corresponds to what is being pointed at.