ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Well there are a few things to do, and note what you wrote is C not C++. (Subtle difference, ) To maintain compatibility with your main() you'll want to not make newpw a pointer, rather an array... like this
And this program suffers from a buffer overflow too in main() from char entered. What if I enter a password that is 1024 characters long? Think of a solution for that. Also note that a bash script that uses mkpasswd would probably be easier to write, more effient, and more secure.
portability. There are more C compilers out there than c++ compilers. Once upon a time the gnu c++ compiler generated slower code, even when invoked on valid C -- I don't know if that's still true. Still, if you are going to require a c++ compiler you might was well make use of the stl <string> class or at least switch to operator "new" and "delete" instead of malloc/calloc/free. If your code gets linked to other peoples' projects, it's doubly important for it to not be schizophenic about it's c or c++ness, as they link differently.