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 |
What is the package for freshers(Non IIT) in amazon(hyderabad). And what is the same for those who are a contract employee.
What does #pragma once mean?
Is a pointer a kind of array?
What is struct node in c?
Prove or disprove P!=NP.
Is Exception handling possible in c language?
Can we use visual studio for c?
What is a protocol in c?
How to print "I Love My India" without using semi colon?
char ch=10;printf("%d",ch);what is the output
What is the purpose of macro in C language?
A float occupies 4 bytes in memory. How many bits are used to store exponent part? since we can have up to 38 number for exponent so 2 ki power 6 6, 6 bits will be used. If 6 bits are used why do not we have up to 64 numbers in exponent?