Hi,
I wanted to know whether it is possible to use the system() function to execute DOS commands when using DEV compiler, if yes please let me know how ?
Reagards,
Vinith
Printable View
Hi,
I wanted to know whether it is possible to use the system() function to execute DOS commands when using DEV compiler, if yes please let me know how ?
Reagards,
Vinith
Of course. You type system("command you want to happen"). system is found in <stdlib.h>, so be sure to include that header.
Sometimes its kind of cool to just compile code to see what happens. There is a bliss involved with trying out something just to see if it will work and seeing that it does in fact work as you planned. I say this with no sarcasm intended, but don't let us rob you of the joy of discovery.
He may not have "DEV compiler" at hand to experiment. I certainly don't so I can't be 100% sure system() is available there.
system() is a standard C function, though. It should be there.
Is it? Can the standard for C dictate that a functioning DOS shell be available? For example on some minimal embedded controller?
Good question. The answer is no. The standard simply dictates which functions should be available and how they should work. Not specifically how they need to work internally or how they are externally manifested. So though your system() function is standard. The parameter string that you pass into that function may be entirely implementation specific or platform specific.
Then you agree that your answer to vinith98 was made using assumptions as opposed to certain knowledge about "DEV compiler", bacause, at best, we have no idea what the target executing environment will be.
>> system() function to execute DOS commands
ho ho... You tricky guy! Nice catch. Alright nonoob, you get to wear the official "Mr. Observant" sombrero. People will be able to behold your cunning from great distances.
If I go out on a limb with another assumption and say he is probably meaning he is using the Dev-C++ IDE (which isn't even a compiler) then I can safely say that my assuming the rest is fair since Dev-C++ is for windows exclusively.
Oh I see. You overlooked the OP's "to execute DOS commands" but instead cited the function system()'s existence as part of ANSI standard regardless. Fair enough. You are likely correct (I haven't looked up the standard).
I took them to be one and the same... a package if you will. I guess under some systems and circumstances, the system() function can accept any string/word/token commands and then execute whatever the prevailing system shell was, or emulated... even if the commands were "XAGD$%$$G" to list the directory, or whatever.
I wasn't looking for people to behold my cunning at great distances. Although the prospect seems alluring.
Well I guess we both need to pay a little more attention to original posters... Its easier to get more involved with the wild tangents the thread has steered off into than to address the needs of the poor student who is frantically trying to get their code to compile. Though in this case the OP should have just compiled a program something like this:
Example:
Code:#include <stdlib.h>
#include <string.h>
int main(void)
{
char buffer[4096];
while(fgets(buffer, sizeof(buffer), stdin))
{
strtok(buffer, "\n");
if(!strcmp(buffer, "quit"))
return EXIT_SUCCESS;
system(buffer);
}
return EXIT_SUCCESS;
}
Novel use of strtok. I thought the manual said it returned the token... I never thought it would mash the contents of the original buffer in the process... (in this case, put a '\0' where the '\n' was).
Yeah I don't remember who I learned that technique from, but it has served me well over the years and it was definitely something I picked up here. I am wanting to say Prelude got me doing that. Either her or Cornedbee. One of those lofty girls... I remember that much.