In my program i get to 2 paths, one is a path of a directory which contains all kinds of files. Whenever I find a c file I compile it. The second path is of an input txt file. lets say something like this:
home/dvir/workspace/assignment1/students/ -(directory)
home/dvir/workspace/tests/input1.txt/ -(input txt file)
here is part of my code:
void listdir(const char *name, int indent)
{
char path[80];
char cmd[4096 + 2*80];
DIR *dir;
struct dirent *entry;
if (!(dir = opendir(name)))
return;
while ((entry = readdir(dir)) != NULL) {
if (entry->d_type == DT_DIR) {
char path[1024];
if (strcmp(entry->d_name, ".") == 0 || strcmp(entry->d_name, "..") == 0)
continue;
snprintf(path, sizeof(path), "%s/%s", name, entry->d_name);
printf("%*s[%s]\n", indent, "", entry->d_name);
listdir(path, indent + 2);
} else {
printf("%*s- %s\n", indent, "", entry->d_name);
snprintf(path, sizeof(path), "%s/%s", name, entry->d_name);
snprintf(cmd, sizeof(cmd), "gcc -c %s -o %s.o", path, path);
if (system(cmd) == 0) {
printf("Compiled %s to %s.o\n", path, path);
}
}
}
closedir(dir);
}
It goes recursivly over the directory and compiles all the files, I saved the input.txt directory in a char array and called it input. now lets assume a have a c program I compiles and got the ashly.c.o file. how can I run this program using the txt file as an input?(and how do I actually get access to that compiled program?) for example: let's say the ashly.c.o gets 2 numbers from the user and multiples them. I want to use the input.txt file to be these 2 numbers and save the output as a new txt file.(so that I can read it latter) I have found some ofthis answers but in my case I don't want to use freopen() function (just open) and I need I a way to access the compiled file from my program... Any help would be appreciated.