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 oops c?
Write a function which takes as parameters one regular expression(only ? and * are the special characters) and a string and returns whether the string matched the regular expression.
I came across some code that puts a (void) cast before each call to printf. Why?
Study the code: void show() main() { show(); } void show (char *s) { printf("%sn",s); } What will happen if it is compiled & run on an ANSI C Compiler? A)It will compile & nothing will be printed when it is executed B)it will compile but not link C)the compiler will generate an error D)the compiler will generate a warning
Program to find the sum of digits of a given number until the sum becomes a single digit. (e.g. 12345=>1+2+3+4+5=15=>1+5=6)
What should malloc() do?
for(i=0;i=printf("Hello");i++); printf("Hello"); how many times how will be printed?????????
What is pointers in c with example?
How can I get the current date or time of day in a c program?
Write a program to find whether the given number is prime or not?
Why main is not a keyword in c?
What are the different types of control structures?