[SOLVED] [!] How to combine values in variable, text, int and other data in system(); (C).
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.
the filename array is 128 long. So buffer overflow is impossible
Originally Posted by Celyr
Look how many nested if I had to add! That's just lol
One of the major causes of bad programming is focusing on just the exact current situation instead of considering the likely evolution of similar situations.
That is especially bad where it leads to beginner programming styles that scale up into land mines for real size projects. I think that applies to both the styles that Celyr is advocating in these comments.
Originally Posted by NevemTeve
2. free (NULL) might be problematic on some old/exotic platforms, so it is wise to make a habit of checking
Another major cause of bad programming is over generalizing to cover theoretical issues that will never arise in the evolution of the current work. Excess code distracts from the smooth flow of the necessary code and increases the probability of bugs.
Any of those old/exotic platforms support vasprintf ?
No two experts will agree on the exact boundary between properly generalizing your code and over generalizing your code. But, the issues are real, not just a matter of opinion. Putting that boundary in a worse place results in worse programming.
I'm surprised no one has brought up the solution that removes the requirement for sprintf() + system(). If all of the arguments are already present, and you just want to launch an editor, then why not use the arguments in a call to one of the exec() (following fork(), of course) system call family? This has the efficiency gain of not loading a shell to load an editor, when all you really wanted was the editor.
I find it interesting how often this is done, as well as how often system() is used to accomplish that which can be done by the language used to make the call (although this is not one of those cases).