how do you redirect stdout value from a program to a file?
Answer / ataraxic
int main(int argc, char *argv[], char *envp[])
{
char *p;
int fd = open("/tmp/mydata", O_CREAT|O_WRONLY);
if ( fd < 0 ) {
perror("open");
return -1;
}
/*
* close(2) system call deletes a descriptor from
* the per-process object reference table. In the
* per-process object reference table, stdin,
* stdout,stderr were placed at positions 0,1,2
* respectively.
*/
close(1);
/*
* Place our file descriptor at the place of stdout.
* Read man dup(2).
*/
dup(fd);
/*
* printf(3) is ultimately calling write(2) with
* first argument as 1
*/
printf("Hello there!\n");
p = getenv("MDEV");
if (p != NULL)
printf("MDEV is: %s\n", p);
p = getenv("SUBSYSTEM");
if (p != NULL)
printf("SUBSYSTEM is: %s\n", p);
return 0;
}
| Is This Answer Correct ? | 1 Yes | 0 No |
can u give me the good and very optimised code for a car racing game?
write a program to generate address labels using structures?
What is pointer in c?
in iso what are the common technological language?
What is a pointer variable in c language?
what is difference between declaring the pointer as int and char in c language?
Design a program using an array that lists even numbers and odd numbers separately from the 12 numbers supplied by a user.
main() { int i,j,A; for(A=-1;A<=1;A++) prinf("%d\t",!!A); }
explain memory layout of a C program
What is the right way to use errno?
What is an auto variable in c?
Is sizeof a keyword in c?