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.

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

May be interested

  • The function bsearch () in CPhoto of The function bsearch () in C
    void function * bsearch (const void * key, const void * base, nitems, size, int (* compar) (const void *, const void *)) looks for an array of nitems objects, its original member is point to by base, for a member that connects the object pointed to by the key. the size of each array element is determined by size.
  • The qsort () function in CPhoto of The qsort () function in C
    void qsort function (void * base, so-phan-tu, kich-co, int (* compar) (const void *, const void *)) arranges an array.
  • Function abs () in CPhoto of Function abs () in C
    the function int abs (int x) returns the absolute value of integer x.
  • Div () function in CPhoto of Div () function in C
    div_t div function (int numer, int denom) divides numer numerator for denom.
  • Labs () function in CPhoto of Labs () function in C
    function long int labs (long int x) returns the absolute value of x.
  • The function ldiv () in CPhoto of The function ldiv () in C
    the div_t div function (long int numer, long int denom) divides the numerator numer to denom.