System () function in C

The int system (const char * command) function passes the command name or program name specified by the command to the host environment to be executed by the Command processor and returned after the command is completed.

The int system (const char * command) function passes the command name or program name specified by the command to the host environment to be executed by the Command processor and returned after the command is completed.

Declare the system () function in C

Below is the declaration for system () in C:

 int system ( const char * command ) 

Parameters

command : This is the string containing the command name.

Returns the value

The value is returned to -1 if there is an error, and if successful, returns the state of the command.

For example

The following C program illustrates how to use the system () function to list all files and directories in the current directory on a Windows device:

 #include #include #include int main () { char command [ 50 ]; strcpy ( command , "dir" ); system ( command ); return ( 0 ); } 

Compile the C program in the Window environment to see the result.

According to Tutorialspoint

Previous article: Function getenv () in C

Next lesson: Function bsearch () in C

4 ★ | 1 Vote