[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.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Introduction to Linux - A Hands on Guide
This guide was created as an overview of the Linux Operating System, geared toward new users as an exploration tour and getting started guide, with exercises at the end of each chapter.
For more advanced trainees it can be a desktop reference, and a collection of the base knowledge needed to proceed with system and network administration. This book contains many real life examples derived from the author's experience as a Linux system and network administrator, trainer and consultant. They hope these examples will help you to get a better understanding of the Linux system and that you feel encouraged to try out things on your own.
Click Here to receive this Complete Guide absolutely free.
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).