log.cpp

来自「OMNET++仿真三色算法的源码,三色算法是无线传感器中一个典型的分簇算法」· C++ 代码 · 共 81 行

CPP
81
字号

#include "h/log.h"



void Log(char* logdata)
{
	FILE* fout = fopen("Application.log", "a+");

//	if(Length() > 512) logdata[512]=0x00;

	fprintf(fout, logdata);

	fclose(fout);
}

void  LogPos(int id, int posX, int posY)
{
	FILE* fout = fopen("Positions.ini", "a+");

	fprintf(fout,"%d=%d,%d\n", id, posX, posY);

	fclose(fout);

}
void  GetPos(int id , int& x, int& y)
{
	FILE* fout = fopen("Positions.ini","r");
	char strLine[80], tmpstr[80];
	char *pos;
	int i, fid;
		
	x = 0; y = 0;
	while(!feof(fout))
	{
		memset(strLine, 0x00, sizeof(strLine));
		memset(tmpstr, 0x00, sizeof(strLine));

		fgets(strLine, 80, fout);
		pos = strLine;

		
		i=0;
		while((*pos != '=')&&(*pos != 0x13))
		{
			tmpstr[i++] = *pos++;
		}

		
		fid = (int)atof(tmpstr);
		if(fid != id) continue;
		
		pos++;
		
		i = 0;
		memset(tmpstr, 0x00, sizeof(tmpstr));

		while((*pos !=',')&&(*pos != 0x10)&&(*pos != 0x13))
		{
			tmpstr[i++] = *pos++;
		}
		
		x = (int)atof(tmpstr);


		pos++;
		strcpy(tmpstr, pos);

		y = (int)atof(tmpstr);
		

		//sprintf(tmpstr, "[%d] = [%d], [%d]\n", id, x, y);
		

		//Log(tmpstr );
		break; //找到了就跳出来吧
	}
	
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?