I'm trying to use the system call to append an arbitrary number of files to one specific file... when I attempt to run the program i get the error:
sh: addints.o: not found
sh: main.o: not found
sh: rbyswt.o: not found
sh: readint.o: not found
sh: writeint.o: not found
sh: writestr.o: not found
all the files (addints.o, main.o...) are located in the directory, I can't figure out why the system call can't find these files, I even changed the system call to do a "ls" call to see if it was running the command in the current directory and it printed out said files it could not find.
disregard all the extra functions and variables as I might end up using them again if this attempt at appending the files ends up not working.
Ive attempted other ways of appending these files with no luck and I figured this way couldn't fail but I guess I'm just having bad luck.
int main(int argc, char* argv[]){
struct stat st;
int i = 1, j = 0;
int n = argc - 1;
long size[n];
int num;
char *str;
FILE *oFile[n];
FILE *command;
FILE *combined = fopen("combinedObjects.o", "w");
for(i = 0; i < n; i++){
str = ("cat %s >> combinedObjects.o", argv[i]);
system("ls");
}
return 1;
}
The other way I was trying to do this was through this loop but I'm getting a segmentation fault midway through copying main.o for some reason I can't figure out.
char ch;
FILE *oFile[n];
FILE *combined = fopen("combinedObjects.o", "w");
for(i = 0; i < n; i++){
oFile[i] = fopen(argv[i+1], "r");
while(( ch = fgetc(oFile[i])) != EOF)
fputc( ch, combined );
}