"Manish" <> writes:
[...]
> okay now let's see the '10' gets stored in ags and 'finy' which needs
> 5 (4 bytes for "finy" and 1 extra byte for '\0') bytes of storage
> space, you try to store it in 'nms' which has how much space ... ?
> (Ans. 1 byte)
The declaration of nms was
char *nms=" ";
so nms points to *two* bytes (' ' and '\0'). But, as someone else
already pointed out, you're not allowed to write to those bytes,
because they're part of a string literal. (You *might* get away with
it, but it's undefined behavior.)
Another comment: white space can make your code easier to read.
Rather than
char *nms=" ";
try:
char *nms = " ";
And so on.
--
Keith Thompson (The_Other_Keith)
kst- <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"