首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >如何将代码的输出重定向到pdf或代码块中的文本文件?

如何将代码的输出重定向到pdf或代码块中的文本文件?
EN

Stack Overflow用户
提问于 2019-07-22 00:38:28
回答 1查看 201关注 0票数 0

我试图打印我的代码输出的硬拷贝,但我不确定在我的代码中写入什么才能使输出在显示后立即转换为pdf或txt文件。

下面的代码只是我整个项目的一部分。这将生成我想要在硬拷贝上显示的输出。

代码语言:javascript
复制
float totaldinein()                                                         
//This function is to calculate the total price of DINING IN including the 5% government tax and 10% dining in charges.
{
    system("cls");
    printf("Select your payment method:1--> Cash Payment     2--> Credit Card Payment\n");
    scanf("%d",&t);

    switch (t)
    {
    case 1: total1 += (faj+taco+tost+chim+flau+burr+fried)*1.15;                   
    //Calculation for grand total with government taxes,and cash payment.


                printf("    Item                Price of 1     Total Price \n");
                printf("      Fajitas             8.00      $%.2f\n",faj);
                printf("      Tacos               5.00      $%.2f\n",taco);
                printf("       Tostadas            7.00      $%.2f\n",tost);
                printf("       Chimichanga         12.00      $%.2f\n",chim);
                printf("      Flautas             10.00      $%.2f\n",flau);
                printf("       Burrito             8.00      $%.2f\n",burr);
                printf("      Fried ice cream     5.00       $%.2f\n",fried);
            printf("\nThe Total is $%.2f\n\n",total1);

            break;
    case 2: total1 += (faj+taco+tost+chim+flau+burr+fried)*1.18;                   
            //Calculation for grand total with government taxes,and credit card payment.

                printf("    Item                Price of 1     Total Price \n");
                printf("      Fajitas             8.00      $%.2f\n",faj);
                printf("      Tacos               5.00      $%.2f\n",taco);
                printf("       Tostadas            7.00      $%.2f\n",tost);
                printf("       Chimichanga         12.00      $%.2f\n",chim);
                printf("      Flautas             10.00      $%.2f\n",flau);
                printf("       Burrito             8.00      $%.2f\n",burr);
                printf("      Fried ice cream     5.00       $%.2f\n",fried);
            printf("\nThe Total is $%.2f\n\n",total1);

            break;



    default: system("cls");
             printf("\nInvalid Error");
    }

}

float totaltakeout()                                                        
//This function is to calculate the  total price of TAKE AWAY including the 5% government tax and 5% dining in charges.
{
    system("cls");
    printf("Select your payment method:1--> Cash Payment     2--> Credit Card Payment\n");
    scanf("%d",&t);

    switch (t)
    {
        case 1: total1 += (faj+taco+tost+chim+flau+burr+fried)*1.10;               
                //Calculation for grand total with government taxes,and cash payment.
                printf("    Item                Price of 1     Total Price \n");
                printf("      Fajitas             8.00      $%.2f\n",faj);
                printf("      Tacos               5.00      $%.2f\n",taco);
                printf("       Tostadas            7.00      $%.2f\n",tost);
                printf("       Chimichanga         12.00      $%.2f\n",chim);
                printf("      Flautas             10.00      $%.2f\n",flau);
                printf("       Burrito             8.00      $%.2f\n",burr);
                printf("      Fried ice cream     5.00       $%.2f\n",fried);
                printf("The Total is $%.2f\n\n",total1);

                break;



        case 2: total1 += (faj+taco+tost+chim+flau+burr+fried)*1.13;               
                //Calculation for grand total with government taxes,and credit card payment.

                printf("    Item                Price of 1     Total Price \n");
                printf("      Fajitas             8.00      $%.2f\n",faj);
                printf("      Tacos               5.00      $%.2f\n",taco);
                printf("       Tostadas            7.00      $%.2f\n",tost);
                printf("       Chimichanga         12.00      $%.2f\n",chim);
                printf("      Flautas             10.00      $%.2f\n",flau);
                printf("       Burrito             8.00      $%.2f\n",burr);
                printf("      Fried ice cream     5.00       $%.2f\n",fried);
                printf("The Total is $%.2f\n\n",total1);

                break;

        default: system("cls");
                 printf("\nInvalid Error");

    }
}
EN

回答 1

Stack Overflow用户

发布于 2019-07-22 09:21:15

只需运行程序./ program.exe即可。

但是在命令行上/从终端执行这个程序> mytextfile。

然后你所有的程序输出将被保存在文本文件中。

在程序中做同样的事情会相当复杂,但仍然是可行的。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/57135081

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档