how do you redirect stdout value from a program to a file?
Answer Posted / 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 |
Post New Answer View All Answers
What are loops c?
Explain continue keyword in c
What are the types of type specifiers?
the portion of a computer program within which the definition of the variable remains unchanged a) mode b) module c) scope d) none
a formula,a series of steps,or well defined set of rules for solving a problem a) algorithem b) program c) erdiagram d) compiler
explain how do you use macro?
Difference between goto, long jmp() and setjmp()?
Write a C program that will accept a hexadecimal number as input and then display a menu that will permit any of the following operations to be carried out: Display the hexadecimal equivalent of the one's complement. (b) Carry out a masking operation and then display the hexadecimal equivalent of the result. (c) Carry out a bit shifting operation and then display the hexadecimal equivalent of the result. (d) Exit. If the masking operation is selected, prompt the user lor the type of operation (bitwise and, bitwise exclusive or, or bitwise or) and then a (hexadecimal) value for the mask. If the bit shifting operation is selected. prompt the user for the type of shift (left or right), and then the number of bits. Test the program with several different (hexadecimal) input values of your own choice.
Do you know the use of 'auto' keyword?
What is methods in c?
When the macros gets expanded?
Explain what is meant by 'bit masking'?
application attempts to perform an operation?
How is pointer initialized in c?
What does dm mean sexually?