c笔记一

[size=small][color=brown]c的一些笔记[/color][/size]
[size=medium]1:声明数组 ,一定要初始化memset();
eg:char buf[12][10];
memset(buf,'\0,sizeof(buf)');
2:声明指针,给了值再用(貌似很简单可我犯错了)
eg: struct qiao * P;
p=(struct qiao *)maloc(sizeof(struct qiao));
p是可以用的。
3;memcpy函数 memcpy(void *desc,void*src,int num);
desc 和src的空间不能重叠,否则会覆盖src的部分值
4:c中的字符串处理;
c的字符串用char数组表示,一定要在数组末尾加个'\0';

5:字符串和数值的转换
[/size]

//把buf的数据放到struct gpsData中
/*
*提取年月日
*/
gpsData->year=(int)(atol(buf[8])%100);
gpsData->month=(int)((atol(buf[8])%10000-gpsData->year)/100);
gpsData->day=(int)(atol(buf[8])/10000);




/*
*提取时分秒毫秒
*/
gpsData->hour=((int)atof(buf[0]))/10000;
gpsData->second=((int)atof(buf[0]))%100;
gpsData->minute=(((int)atof(buf[0]))%10000-gpsData->second)/100;
gpsData->minisecond= (int)((long)(atof(buf[0])*1000)%1000);

/*
*提取经度和纬度
*/
char temp[3];
char *tempPoint;

memset(temp,'\0',sizeof(temp));

memcpy(temp,buf[4],2);
temp[3]='\0';

gpsData->longitude=atoi(temp);

tempPoint=buf[4];
gpsData->m_longitude=atof(tempPoint+2);



memcpy(temp,(char *)buf[2],2);
temp[3]='\0';
gpsData->latitude=atoi(temp);
tempPoint=buf[2];
gpsData->m_latitude=atof(tempPoint+2);
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值