[prog] Strings in C

Jenn Vesperman jenn at anthill.echidna.id.au
Sat Oct 19 08:53:11 EST 2002


On Fri, 2002-10-18 at 23:31, k.clair wrote:
> Hello,
> 
> I don't have an answer, but I do have another question :-D
> 
> I've only learned a tiny bit of C, but I was under the impression that
> character arrays had to have the \0 character at the end of them in
> order to be treated like a string.  Well, this confuses me ... do they
> *have* to end with \0, or is it just convenient to have at the end for
> working with them?

The answer to that also answers this:

> - > Problem number 1: If the string the user wrote is less
> - > then 40 characters the end of the l_email string
> - > sometimes contains "junk"-characters. How can I get
> - > rid of those? I want the rest of the string empty.

The \0 means 'this is the end of the real string, everything after this
is junk'.

So search for the \0, then discard everything else. Or let the strings
library do that for you, if you're trying to do things it has functions
for.




Jenn V.
-- 
    "Do you ever wonder if there's a whole section of geek culture 
        	you miss out on by being a geek?" - Dancer.

jenn at anthill.echidna.id.au     http://anthill.echidna.id.au/~jenn/





More information about the Programming mailing list