Hi,
I am working with c program that uses "touch" unix command. But, the command executes only in the second time I run the program. I tried extracting the command in a separate file and the other code in another file and running them separately, and that worked. I wonder why when I join them in one programe not working.
The command code:
Code:
#include <stdlib.h>
int main (void)
{
system (" touch file ");
return 0;
}
This is part of the code: where I use popen() function for paths of files and implemeting "touch" command for each path:
Code:
while (1)
{
if (fgets (l, 260, ptr) == NULL)// get the path of the first file
break;
l [strlen (l) -1] = '\0';// convert it to string
strcpy (command, "touch ");// using touch command
strcat (command, l);
system (command);
fp = open (l, O_RDONLY);// Then opening the file
if (fp == -1)
{
printf("Could not open file \n");
exit(1);
}
}
I need to use touch command for each file before opening it