如何将输出存储到文件中 [英] How do I store the output to a file
问题描述
如何将以下程序的输出写入文件:
**程序基本上要求用户输入矩阵的值然后显示他们。**
该计划是:
#include< stdio.h>
main()
{
int a [10] [10];
int i,j,n;
printf(输入n< 10 \ n的值);
scanf(%d,& n);
for(i = 0; i< n; i ++)
{
=for(j =0; j< n; j ++)
scanf(%d,& a [i] [j]);
=}
=for(i = 0; i< n; i ++)
printf(%d,a [i] [j]);
=printf(\ n );
=
=
i =know =how = to =write ==code =但=i =dont =can =store =contents =of =program =a =文件。
=
can =someone =kindly =tell =me =put =in = F ile?what =are =命令
=需要
any = help =will =be =有用
< b =>我尝试了什么:
程序给我输出但我不明白如何将输出存储到文件中。
有什么方法我将其存储在一个文件中。
How to write the output of the following program to a file:
**The program basically asks the user to input the values of a matrix and then displays them.**
The program is :
#include<stdio.h>
main()
{
int a[10][10];
int i,j,n;
printf("Enter the value of n<10\n");
scanf("%d",&n);
for(i=0;i<n;i++)
{
="" for(j="0;j<n;j++)
" scanf("%d,&a[i][j]);
="" }
="" for(i="0;i<n;i++)
" printf("%d,a[i][j]);
="" printf("\n");
=""
=""
i="" know="" how="" to="" write="" the="" code="" but="" i="" dont="" can="" store="" contents="" of="" program="" a="" file.
=""
can="" someone="" kindly="" tell="" me="" put="" in="" file?what="" are="" commands
="" needed
any="" help="" will="" be="" useful
<b="">What I have tried:
The program gives me the output but I dont understand how can I store the output to a file.
Is there any way I store it in a file.
推荐答案
使用 C库函数fprintf () [ ^ ] - 有样本底部的代码。
Use C library function fprintf()[^] - there is sample code at the bottom.
最简单的方法是将可执行文件的标准输出重定向到一个文件(例如,参见:如何将命令提示输出重定向到文件[简单] [ ^ ])。
The simplest way is to redirect the standard output of the executable to a file (see, for instance this: How to Redirect Command Prompt Output to a File [Easy][^]).
这篇关于如何将输出存储到文件中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!