-> DH>char name[41];
-> DH>gets(name);
-> DH>name[41]='\0';
-> DH>printf("%s",name);
->
-> DH>My bad.
->
-> It still is, I'm afraid.
->
-> An array of size 41 has subscripts 0 thru 40, so the 3rd line has a
-> subscript out of bounds.
->
-> Moreover, the gets() function does not limit the transfer to the size
-> of the supplied buffer, since it does not know that size. The use of
-> fgets() instead is much safer.
1: fgets() is for use with files.
2: It works, and works perfectly if you ever bothered to try it.
3: It counts 0 thru 41 standardly. using cin.get() it uses 0 thru 40
because it already accounts for the NULL on the end.
Ok? Try it. You'll see that I am right. I use that all the time.
-Dave
1:3612/333
333:1/1
davidvh@ibm.net
--- PCBoard (R) v15.3/100
---------------
* Origin: Destiny BBS: LightBar Central (1:3612/333)
|