Use the system call to read the path in the read file under Linux

xiaoxiao2021-03-06  58

You can cooperate with Yesterday's analog shell to read the path.txt content read from the enabled file path from the environment variable to / bin; / home / test; #include #include #include #include #include #include #include #define max 8192

INT SLIP (Char * Str, Char * Path [10]) {char * p; INT I, J; Char FullPath [10] [MAX] = {}; p = Str; i = 0; while ((* P) ! = 10) {j = 0; while (* p)! = ';') {FullPath [i] [j ] = * p; p ;} i ; p ;} i = 0; while (i <10 ) {Path [i] = fullpath [i]; i ;} i = 0; while (path [i] [0]! = 0) {Printf ("% D IS% S / N", I, PATH [i ]); I ;} if (path == null) return 0; Return 1;}

INT main () {Int i; char fpath; char * path [10]; file * stream; char Tempstr [MAX] = {}; if ((stream = fopen ("./ path.txt", "r") ) == NULL) {Printf ("can not open file / n"); exit (1);} Printf ("OpenFile IS OK / N"); while (fpath = fgetc (stream))! = EOF) { Tempstr [0] = fpath; if (& TempStr [1], Max, Stream) == NULL) EXIT (1);} Printf ("THE DATA IS% S / N", Tempstr); if (Slip (Tempstr) , PATH) == 0) {Printf ("THE SLIP FAILS / N"); exit (1);} i = 0; While (Path [i] [0]! = 0) {Printf ("Path [% D ] IS% S / N ", I, PATH [I]); i ;} returnif 1;}

转载请注明原文地址:https://www.9cbs.com/read-114035.html

New Post(0)