gpssimulator.c

来自「此程序为GPS数据仿真程序」· C语言 代码 · 共 94 行

C
94
字号

#include "common.h"
#include <stdlib.h>
#include <stdio.h>
#include <minigui/common.h>


/*
* read the file
 * para
 * ft: the file of handle
**len: the lenght 
* 
*/
int getfilestr(FILE* ft,char* p,int len)
{
  
 if(fgets(p,100,ft))
 {
 	return 1;
 	}
 	else
 	{
 		return -1;
 	}
  
  

}
/*
*
*
*/

POINT parsestring(const char  *str)
{
	int len ;
	POINT retval;
	char * head = str;
	len = strlen(str);
	while(*head != ',')
	{
		++head;
	}
	if(!head)
	{
	
		retval.x = 0;
		retval.y = 0;
		return retval;
	}
	*head= '\0';
	retval.x = atof(str)*3600*256;
	retval.y = atof(head+1)*3600*256;
	return retval;
}

/*
*
*
*/

uint8 getsimulatordata(POINT* gpssimdata,int len)
{
    FILE * ft;
    POINT reaxy;
    char readfile[100];
    ft = fopen("data/trace.txt","r");
    if(!ft)
    {
        printf("can't open the file!\n");
       // exit(0);    
    } 
    else
    {
      int i= 0;
      while(getfilestr(ft,readfile,100))
      {
      
          reaxy = parsestring(readfile);
          printf("x = %d,y = %d,i = %d\n",reaxy.x,reaxy.y,i);
          
		  gpssimdata[i] = reaxy;
		  ++i;
          if(i == 105)
          {
              break;
          }    
      }      
    } 
	fclose(ft);
    return 1;
}

⌨️ 快捷键说明

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