用C语言在fprintf语法中调用函数 [英] Calling a function within fprintf syntax in C language

查看:62
本文介绍了用C语言在fprintf语法中调用函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将我的字符串输出打印到一个单独的文件中.我现在遇到的问题是我的代码带有一组字符串的函数,该函数在我的列(纯粹是修饰符)下添加了虚线.如何在fprintf代码中调用此函数?

I'm trying to print my strings output into a separate file. The issue I'm running into right now is the fact that my code carries a function for a set of strings that adds dashed lines underneath my columns (purely cosmetics). How do I call this function inside my fprintf code?

#include <stdio.h>
/* function for the dash-line separators*/
void
dashes (void)
{
printf ("  ----           -----        --------------------     --------------\n");
}
/* end of function definition */

/* main program */
#include <stdio.h>
#include <string.h>
int
main (void)
{
FILE *data_File;
FILE *lake_File;
FILE *beach_File;
FILE *ecoli_Report;
char fileName[10], lake_Table[15],beach_Table[15];  /*.txt file names */

char province[30] = "";         /*variable for the file Lake Table.txt*/
char beach[20]="",beach1[20];   /*variable for the file Beach Table.txt*/
char decision[15] = "CLOSE BEACH";

int lake_data=0,lake_x=0, beach_x=0, nr_tests=0;    /* variables for the file july08.txt */
int province_data=0,prv_x=0;        /* variables for the file Lake Table.txt */
int beach_data=0,bch_x=0;           /* variables for the file Beach Table.txt*/

int j;
double sum, avg_x, ecoli_lvl;
printf ("Which month would you like a summary of? \nType month followed by date (i.e: july05): ");
gets(fileName);
/*Opening the files needed for the program*/
data_File = fopen (fileName, "r");
lake_File = fopen ("Lake Table.txt", "r");
beach_File = fopen ("Beach Table.txt", "r");
ecoli_Report = fopen ("Lake's Ecoli Levels.txt", "w");

fprintf (ecoli_Report,"\n  Lake           Beach          Average E-Coli Level     Recommendation\n");
fprintf (ecoli_Report,"%c",dashes());

推荐答案

dashes()是void返回函数,您将如何获得这行代码?

dashes() is void returning function how will you get this line?

 fprintf (ecoli_Report,"%c",dashes());

如果您需要在文件中打印该行,请制作原型并像这样调用

If you need to print the line in the file, make the prototype and call like this,

 void dashes(FILE *fp){
    fprintf(fp,"------------------\n");
 }

删除此行.

 fprintf (ecoli_Report,"%c",dashes());

然后将调用方式更改为这样,

And change that calling into like this,

 dashes(ecoli_Report);

否则只需这样做,

 fprintf(ecoli_Report,"----------------");

这篇关于用C语言在fprintf语法中调用函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆