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 |
Is the C language is the portable language...If yes...Then Why...and if not then what is problem so it is not a Portable language..???
Magic square
Write a program to input the price of 1 burger and the number of burgers eaten by a group of friends .print the total amount to be paid by the group?
f(x,y,z) { y = y+1; z = z+x; } main() { int a,b; a = 2 b = 2; f(a+b,a,a); print a; } what is the value of 'a' printed
why in C,C++'s int size is 2 byte and .net(c#) int Size is 4 byte?
program for swapping two strings by using pointers in c language
hi send me sample aptitude papers of cts?
Write a C program to fill a rectangle using window scrolling
Write a program to write a given string in maximum possibilities? i.e str[5]="reddy"; i.e we can write this string in 120 ways for that write a program
What is the use of header files?
what is the syallabus of computer science students in group- 1?
What is the best style for code layout in c?