system : <stdlib.h> library function

The function int system(const char *command); transfers the command name specified by command to the host environment to be executed by the command processor. It returns after the command has been completed in host environment.

Function prototype of system

int system(const char *command);
  • command : This is a null terminated string containing the system command to be executed.

Return value of system

If command is not NULL, then function returns the status code of the command otherwise -1 in case of error.
If command is NULL, then function returns a non-zero value in case a command processor is available otherwise zero.

C program to show the use of system function

The following program shows the use of system function to run system commands in host environment.

#include <stdio.h>
#include <string.h>

int main () {
   char command[100];
   printf("Enter any system command as string\n");

Program Output
Enter any system command as string