Where oh where is my directory
Juergen Wagner
gandalf at csli.STANFORD.EDU
Sat Mar 25 14:00:30 AEST 1989
In article <7712 at pyr.gatech.EDU> perrone at loligo.UUCP (Perrone Ford) writes:
>What I am trying to accompish is to read the directory
>entries into a buffer and then print the buffer out in the
>middle of a graphics routine
Basically, there are two ways: call a program like "ls" (UNIX), or do it
yourself. I reckon your problem is not an ANSI/non-ANSI problem, it's more
an operating system problem.
>#include <stdio.h>
>#include <grphics.h> /* Maybe curses */
>main ()
>{
>char *listing;
>listing = system("dir");
>initgraph = DETECT;
>initgraph(&graphdriver, &graphmode);
>outtext(listing);
>}
Sure your screen gets trashed. The problem is that your call to "dir" doesn't
return a list of file names neatly packed into a string, it returns an
integer (probably :-). I have no idea what exactly is possible on your system
but try to look for one of the following:
(a) Something like opendir(), readdir(), closedir() to
access directory entries, and collect them into a
string. Even better, print them as you read them.
(b) Something forking a subprocess which allows you to
collect the output of the subprocess in some way
(popen would be nice).
(c) In the worst case, call a program doing what you want,
have the program write its output to a file, and read
that file. I can promise you that it'll be sloooow but
it will work.
Good luck,
--
Juergen Wagner gandalf at csli.stanford.edu
wagner at arisia.xerox.com
More information about the Comp.lang.c
mailing list