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 about "char *(*(*a[])())();"
Explain modulus operator.
consider the following C code main() { int i=3,x; while(i>0) { x=func(i); i--; } int func(int n) { static sum=0; sum=sum+n; return(sum); } the final value of x is
Is c is a low level language?
What is meant by keywords in c?
What is the output of below code? main() { static in a=5; printf("%3d",a--); if(a) main(); }
Why can’t constant values be used to define an array’s initial size?
In a byte, what is the maximum decimal number that you can accommodate?
What should be keep precautions while using the recursion method?
What do you mean by command line argument?
how to solve "unable to open stdio.h and conio.h header files in windows 7 by using Dos-box software
Explain 'far' and 'near' pointers in c.