所以我正在编写这个程序,我不知道如何通过引用或值传递。我只需要将值从一个函数(processFile)传递给另一个函数(printReport)。任何有关如何做到这一点的帮助将不胜感激。
#include <stdio.h>
#include <stdlib.h>
void printInstructions();
int processFile(FILE *fileIn);
void printReport();
int main(void)
{
FILE *fileIn;
int words = 0,
lines = 0,
characters = 0,
sentences = 0;
printInstructions();
fileIn = fopen("input09.txt", "r");
if(fileIn == NULL)
printf("\n\nERROR\n\n");
processFile(fileIn);
printReport(words, lines, characters, sentences);
}
void printInstructions()
{
printf("\n Program reads a file and returns the number of \n");
printf("lines, words, characters, and sentences in the file.\n\n");
return;
}
int processFile(FILE *fileIn)
{
int sentences = 0,
words = 0,
lines = 0,
characters = 0,
ch;
while(ch != EOF)
{
ch = fgetc(fileIn);
if(ch == '\n' || ch == 60)
lines++;
if(ch == '.')
sentences++;
if(ch != '.' || ch != ' ' || ch != '\n')
characters++;
if(ch == ' ')
words++;
}
return 0;
}
void printReport()
{
printf("This file contains NUMBER lines.\n");
printf("This file contains NUMBER words.\n");
printf("This file contains NUMBER characters.\n");
printf("This file contains NUMBER sentences.\n\n");
return;
}