我的main.c是调用函数ReadLine(Line)的地方。这是代码......
#include "Definition.h"
#include "ExternalVar.h"
#include <stdio.h>
#include <stdlib.h>
char Line[MaxLine]; /* one line from the file */
int NChars = 0, /* number of characters seen so far */
NWords = 0, /* number of words seen so far */
NLines = 0, /* number of lines seen so far */
LineLength; /* length of the current line */
int word_count = 0,
line_count = 0,
character_count = 0;
extern int Readline(),CountWord(),CountUpdate();
int main(int argc, char *argv[]) {
FILE *fp;
fp = fopen(argv[1],"r");
while(fscanf(fp,"%s",Line) != EOF)
character_count = Readline(Line);
printf("character count for this line is : %d \n",character_count);
printf("%s\n",Line);
fclose(fp);
}
这是Readline.c
文件,我的问题是如何进行循环来计算每行的字符数并将值返回给Main.c
#include "Definition.h"
#include "ExternalVar.h"
#include <stdio.h>
int Readline(char *Line) {
int internal_count = 0;
for (internal_count = 0; *Line != '\0'; Line++, internal_count++);
return internal_count;
}
这将返回行上的字数而不是字符数。