c的一些笔记
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:字符串和数值的转换
//把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);
转自 http://kulinglei.javaeye.com/blog/392389