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 will be the output of" printf("%d%d",scanf("%d% d",&a&b));"
Explain what is gets() function?
What is the difference between int main and void main in c?
struct node { int *a; char *b; char array[12]; }; struct node m,*n; assign the value in *a,*b,char array[12]
What are multidimensional arrays?
Define C in your own Language.
Write a program which has the following seven functions. The functions should be: • main() this calls the other 6 functions • fget_long() a function which returns a long data type from a file • fget_short() a function which returns a short integer variable from a file • fget_float() a function which returns a floating point variable from a file • fprt_long() a function which prints its single, long argument into a file • fprt_short() a function which prints its single, short argument into a file • fprt_float() a function which prints its single, floating point argument into a file. You should use fscanf() to get the values of the variables from the input (the file) and fprintf() to print the values to the other file. Pay attention to using the correct format for each of the data types.
What is wild pointer in c?
How are pointers declared in c?
Using which language Test cases are added in .ptu file of RTRT unit testing???
size maximum allocated by calloc()
what is the different between data structure and data type?