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 hungarian notation? Is it worthwhile?
Write a Program to find whether the given number or string is palindrome.
What are predefined functions in c?
c program to subtract between two numbers without using '-' sign and subtract function.
How are structure passing and returning implemented?
write a program that reads lines(using getline), converts each line to an integer using atoi, and computes the average of all the numbers read. also compute the standard deviation.
wt is d full form of c
int main() { int i=1; switch(i) { case '1': printf("hello"); break; case 1: printf("Hi"); break; case 49: printf("Good Morning"); break; } return 0; }
What are the types of variables in c?
What are the types of pointers?
do you think its fraud or original company?
how to make c program without a libary? e.g.#include<stdio.h> libary is not in c progaram.