代码:
头文件print_tools.h
#include<stdio.h>
void printStr(const char *pStr)
{
printf("%s\n",pStr);
}
void printtInt(const int i)
{
printf("%d\n",i);
}
头文件counter.h
#include"print_tools.h"
static int sg_value;
void counter_init()
{
sg_value=0;
}
void counter_count()
{
sg_value++;
}
void counter_out_result()
{
printStr("the result is:");
printtInt(sg_value);
}
main.cpp
#include "print_tools.h"
#include "counter.h"
int main()
{
char ch;
counter_init();
printStr("please input some charactors:");
while((ch=getchar())!='$')
{
if(ch=='A')
counter_count();
}
counter_out_result();
}