c#初学c,指针的问题,谢谢前辈们。
本人熟悉c#,初学c语言,现有一个问题如下:有一个文本文件,格式如下:
Receive from 127.0.0.1 : 2569】:
$GPRMC,090928.00,A,2239.6642,N,11403.3480,E,14.6,175.0,150709,,,*2b
【Receive from 127.0.0.1 : 2570】:
$GPRMC,090929.00,A,2239.6600,N,11403.3486,E,14.0,177.0,150709,,,*2e
Receive from 127.0.0.1 : 2571】:
$GPRMC,090930.00,A,2239.6558,N,11403.3486,E,14.0,177.0,150709,,,*28
Receive from 127.0.0.1 : 2572】:
现在要把该文件的内容读出来,把$和*之间的数据做一些处理。代码如下:
现在编译没有问题,但是运行出错,请高手不吝指点错误。谢谢啦。
#include "stdafx.h"
#define LINE 1000
int _tmain(int argc, _TCHAR* argv[])
{
FILE *fp;
char buf[1024];
if(NULL==(fp = fopen("gps.txt","r")))
{
exit(-1);
}
while(!feof(fp))
{
if(fgets(buf,LINE,fp)!=NULL)
{
const char *p =buf;
if(*p != '$')
{printf("error\n");}
else
{
unsigned char x=0;
const char *p1 =buf;
while(*p1 && *p1!='*')
{
x ^= *p++;
}
printf("%s",x);
}
}
}
fclose(fp);
}