-1

文字列を部分文字列化して変更したい (以下で定義)。

char gps[]="$GPGGA,115726.562,4512.9580,N,03033.0412,E,1,09,0,9,300,M,0,M,,*6E";

まもなく、緯度、経度のデータを取得して増やしたいと思います。

私の歩み

  1. 緯度情報を char または float として取得
  2. lat(char) を float に変換する
  3. float にステップ値を追加する
  4. lat(float) を newlat として char に変換します
  5. newlat を gps[] に挿入する
  6. printf

  char substr[10];  //4512.9580 //#number of char
  memcpy(substr,&gps[19],10); //memcpy from gps char start from 19 take 9 char character
  substr[10]='\0';  //I dont know what makes it
  char lat[10]=???  //I dont know how I will take lat data
  float x;      //defined float value
  x=atof(lat);      //convert string to float
  x=x+0.1;      //add step value to float (4513.0580)
  char newlat[10];  //newlat defined
  sprintf(newlat,x);    //convert to float to string
  ????          //I dont know how I can put into gps[]
4

2 に答える 2

0

これを試して:

char substr[10];
float x;

memcpy(substr,&gps[18],9);
substr[9]='\0';
x=atof(substr);
x=x+0.1;
sprintf(substr,"%.4f",x);
memcpy(&gps[18];substr,9);
于 2014-07-23T09:00:23.437 に答える