我想要一个读入文件并返回ascii值之和的函数。我已经看过此页:我想要一个函数读入文件并返回ASCII值的总和
How to open a file and find the longest length of a line and then print it out
和回答我的问题很可能是我主演的脸,但我不能按照代码足以令它为我工作。另外,如果你能告诉我如何寻找我想要的功能,而不必在这里问这很酷。谢谢。
或者这是我需要建立的东西? 当前代码:
#include <stdio.h>
#include <stdlib.h>
double get_number(int num);
main()
{
double n1,n2,n3;
double average;
printf("\nCompute the ascii average of 3 files\n");
printf("--------------------------------\n");
n1 = get_number(1);
n2 = get_number(2);
n3 = get_number(3);
average = (n1 + n2 + n3)/3;
printf("The average is %0.2f\n",average);
}
double get_number(int num) {
double value = 0;
int c;
printf("Please input entry %i: ", num);
while ((c = getchar()) != EOF) {
value = value + (c);
}
return(value);
}
我们正在做的功课还是什么? – dzen 2010-09-19 22:58:13
你打赌。我至少在尝试。 – pisfire 2010-09-20 00:21:22
另请参阅[SO 3747144](http://stackoverflow.com/questions/3747144/c-assignment-averaging-integers)和[SO 3743444](http://stackoverflow.com/questions/3743444/averaging-3-整数)。 – 2010-09-20 02:48:03