Question

is it possible to save information gather from a sprintf into a variable? The lines of code below are an example to better illustrate my question.

char fileName;
fileName = sprintf(command, "find -inum %i -type f", iNode);

The purpose is to find the file name associated with the inode number, then run "stat" on that file name.

Was it helpful?

Solution

I think you want something like this:

FILE *fp;
char cmd[1024];
char filename[1024];

sprintf(cmd, "find -inum %i -type f", iNode);
fp = popen(cmd);
fgets(filename, sizeof filename, fp);
pclose(fp);

At the end of this code, filename will contain the fist line produced by the cmd.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top