View Single Post
Old Nov 18th, 2005, 6:16 AM   #7
DaWei
Resident Grouch
 
DaWei's Avatar
 
Join Date: Jun 2005
Posts: 6,453
Rep Power: 10 DaWei is on a distinguished road
You are not using scanf in such a way as to prevent overrunning the buffer, which can lead to improper operation and crashing of your program. Your buffer, with a length of 30, can hold a 29-character string, maximum, since your string will require a terminating null if you intend to pass it to a C-string function such as printf or strlen. When you overwrite the terminating null that IS there with your plural ending, you're bound to get odd results, if not a memory violation, because you're not terminating your addition.
__________________
Abstraction doesn't make it impossible to write bad code; it makes it possible to write superior code.
Contributor's Corner: Grumpy on C++ Exceptions DaWei on Pointers
DaWei is offline   Reply With Quote