Use C system function to call system command

Syntax

C system function has the following format.

int system(const char *str);

C system function is from header file stdlib.h.

Description

C system function passes the string as a command to the command processor and returns zero on success or nonzero on error.

Example

Use C system function to call system command. and display the contents of the current working directory in window system:


#include <stdlib.h>
//w  ww.  j a va 2s.co m
int main(void)
{
  printf("%s",system("dir"));
}




















Home »
  C Language »
    Function Reference »




assert.h
ctype.h
math.h
setjmp.h
signal.h
stdio.h
stdlib.h
string.h
time.h
wctype.h