The main problem, of many, that the two
xpath = strcat(argv[argc - 1], ...
concatenate to argv[argc - 1] additional text.
I am certain you are thinking that strcat()
concatenates 2 strings and supplies the combine result as the answer without affecting the inputs. It does not do this, rather, it appends the 2nd parameter to the 1st, returning the first parameter.
Re-write your code to create a buffer workspace.
char xpath[1000];
strcpy(xpath, argv[argc - 1]);
strcat(xpath, "/");
strcat(xpath, argv[i]);
BTW, the sizeof() xpath could be MAXPATHLEN or some other system constant, but that is another question. See #include limits.h
.