/* illustrates how a system command is generated and excuted by a C program */ #include #include #include #define MAXSTRING 100 main() { char command[MAXSTRING], *tmp_file_name; int c; FILE *ifp; tmp_file_name = tmpnam(NULL); /* creates temporary file name */ sprintf(command, "dir > %s", tmp_file_name); printf("Compiled command is %s \n\n", command); system(command); ifp = fopen(tmp_file_name, "r"); while ((c = getc(ifp)) != EOF) putchar(tolower(c)); remove(tmp_file_name); }