output to file
#include <stdio.h>
main() { int i=0; int j; j =4; printf("Value of i and j are %d %d\n",i, j); } Instead of getting i and j printed on the monitor , you can get it printed in the file as well using same printf function. What you need to do is you need to change your standard output to a file? |
Not sure if you're asking this, but you can redirect a program stdout on the shell by:
Code:
./program > outputFile.txt |
Hello friend, you can change the std out in this way:
Code:
#include <stdio.h> If you want redirect the stdout into file, you must insert into fprintf the file descriptor. For example. If *fp is a file descriptor, when you insert into fprintf(fp,".....");, it write output into file |
please elaborate the answer the concept is not clear
|
Quote:
|
There are two main ways to do this:
1) The more flexible option is stated by silendo above. Basically you print to stdout and redirect to a file in bash. This is the way I usually use. 2) Do it in C by opening a file and fprintf to the file instead of stdout. http://www.cplusplus.com/reference/c...stdio/fprintf/ |
All times are GMT -5. The time now is 01:42 AM. |