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 |
Program to find larger of the two numbers without using if-else,while,for,switch
what is the program to display your name in any color?
What is the newline escape sequence?
The file stdio.h, what does it contain?
Explain what is page thrashing?
Write a program that takes a 5 digit number and calculates 2 power that number and prints it.
5 Answers TCS, Vimukti Technologies,
If input is 123 then how to print 100 and 20 and 3 seperately?
Write a program of advanced Fibonacci series.
any string of bits of length 'n' represents a unique non- negative integer between.............?
main() { char *p; p="Hello"; printf("%c\n",*&*p); }
What is extern variable in c with example?
How can I open files mentioned on the command line, and parse option flags?