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

标签 c

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

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

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");

    }
}

最佳答案

只需运行您的程序program.exe,./program。

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

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

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

关于c - 如何将代码的输出重定向到代码块中的 pdf 或文本文件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57135081/

相关文章:

c - 使用 putenv 和 getpid 在 C 中使用 CreateProcess 时出现错误

c - 为什么这个变量的值等于 '0' 而不是 '42?

C strtok() 未正确标记?

c - 缓冲区溢出;避免溢出攻击

c - C 中的函数处理数组

c - 使用 read() 系统调用读取结构内容

c++ - 是否可以在 C++ 中对 C 结构进行子类化并在 C 代码中使用指向该结构的指针?

c++ - 为什么时序会随着输入数据中零的数量而急剧变化?

c - 存储 PPM P3 文件的所有值

c - 优雅地加密/解密脚本的建议?[现在在 Sourceforge 上]