I am trying to write in a file from a terminal until you write "exit". This code copiles, but doesn't work. It doesn't even write a file ! What should I do?
void my_script(char* name, t_Option option)
{
FILE *file;
(void)option;
while (strcmp("/stdin", "exit") != 0)
{
file = NULL;
file = fopen(name,"w");
fprintf(file, "%s", "Writing in a file !\n");
fclose(file);
}
}
Tanks for your help! :)
/*******************/
Here is my solution, tanks to you guys, who reminded me a lot ;)
void my_script(char* name)
{
FILE *file;
char buff[4096];
int len;
file = NULL;
len = 0;
file = fopen(name,"w");
while ((len = read(0, buff, 4096)) != -1)
{
buff[len] = '\0';
if (strncmp(buff, "exit", 4) == 0)
break;
fprintf(file, "%s", buff);
}
fclose(file);
}