How to include a linux command in a C programme?

I tried to write a program which includes the execl function but I failed.
how can I do that?
for example, what should I do if I want to include this command in my C program?
stat -c%y fileName
Thanks!
Do you mean
system("stat -c%y fileName");
Thx Packman. It works.
But is there any other methods because it is supposed the fileNames are written in a text file, so I cannot write a fixed file name inside the C programme.
Read the text file line by line and store the file names into a string.

Then use the .c_str() method provided with the <string> header.

system("stat -c%y fileName.c_str()");

(Note: I don't know if system takes a string or a C-style string. If the above code doesn't work then use a normal string (fileName) )
Last edited on
Thanks eker676
I'm sorry but I'm not sure I understand what you've said
(because I'm a newbie of C, really really sorry)
You can glue strings:
1
2
3
4
char args[32]="fileName.txt"; //put your file name here
char program[32]="stat -c%c ";
strcat(program,args);
system(program);
Thanks Packman, although changing the variable args and program is quite challenging to a newbie like me, it still works=]
It's not so hard just put file name to char args[32];
Good luck :-)
Topic archived. No new replies allowed.