comp.lang.c
[Top] [All Lists]

Re: strcat strncat and strlen

Subject: Re: strcat strncat and strlen
From: Gordon Burditt
Date: Mon, 31 Mar 2008 02:28:52 -0000
Newsgroups: comp.lang.c

>    Why in production code would someone want to know the length of a 
>string? 

Why would you want to check input for validity?  In the case of strings,
that often includes minimum and maximum length constraints.

Why would you want to check if the next word (in a fixed-width font) will
fit on the current line, or whether you must start a new one?

Why would you want to check if there is going to be a buffer overflow
before overflowing it?  This is often related to putting the data
input into a database (C does not define the term 'database' but you
can build one using files).

Why would you want to center a title on a page, in a fixed-width
font?  (Take the width of the page in characters, subtract the
length of the title, divide by 2, round, and print that many spaces,
then the message, then start a new line).



<Prev in Thread] Current Thread [Next in Thread>
Privacy Policy