c - wordexp results if there is no matching file -
I have problems with the use of wordexp if any of these files can not be found , Then he returns as if 1
#include & lt; Stdio.h & gt; # Include & lt; Wordexp.h & gt; #include & lt; String.h & gt; Int main (int argc, char * argv []) {if (argc & lt; 2) return -1; Printf ("Search for% s: \ n", argv [1]); Wordexp_t p; Memset (and P, 0, SizeP); If (wordexp (argv [1], and p, 0)! = 0) return -1; Char ** w = p.we_wordv; Printf ("p.we_offs =% zu \ n", p.we_offs); Printf ("p.we_wordc =% zu \ n", p.we_wordc); (Unsigned int i = 0; i & lt; p.we_wordc; i ++) {printf ("file found:% s \ n", for w [i]); } WordFree (and P); Return 0; } Call this program with ./a.out. "Test * .c" Result
Search for trial * .c: p.we_offs = 0 p.we_wordc = 2 file found: test1.c file found: test2 C but do this . Calling from "test0 / .ac" * .c " results
test0 * .c: p.we_offs = 0 p.we_wordc = 1 Search for file: Test0 * .c
/ Div>
Comments
Post a Comment