background preloader

C Language

Facebook Twitter

Cplusplus.com - The C++ Resources Network. How To: C / C++ Main. How to handle unknow size user input in C. Here are two examples to handle user input in C. 1. scanf This method is easy get attack by buffer overflow, try input some characters which are more than what you declare to experience about what is buffer overflow. 2. fgets This method can protect buffer overflow by limit the character user input.

However, above two methods only can handle normal user input, how about i want to handle user input with 1000 or even more characters? Solution To fix it, uses realloc() to increase memory size dynamically. Below example using dynamic memory allocation(realloc) in C to handle user input in unknown size. Done, now the program can handle unknown size user input easily. Boost C++ Libraries.