1

我有

printf("%12.8f, %12.8f, %6.3f, %04u/%02u/%02u   %i:%i:4.2f\n",sbet.longitude1,sbet.latitude1,sbet.altitude ,myyear,mymonth, myday, sbet.hour, sbet.minute, sbet.second);

在 If 语句中。它会一行一行地产生我想要的东西。但现在我想在最顶部添加一个标题/标题。我是否使用另一个 printf 语句?当我尝试一个简单的

printf("Longitude,", "Latitude," "Elevation," , "UTC Time");

这并没有给我我想要的东西,它只是在每一行加上“经度”以及另一个 printf 语句中的其余参数。

基本上我想得到这个结果

Longitude,   Latitude,   Elevation,   UTC Time
-50.62596165,  67.01225899, 82.948, 2012/05/08   10:0:0.04
-50.62596152,  67.01225906, 82.949, 2012/05/08   10:0:1.04
-50.62596154,  67.01225906, 82.950, 2012/05/08   10:0:2.04
-50.62596148,  67.01225902, 82.951, 2012/05/08   10:0:3.04
-50.62596154,  67.01225907, 82.952, 2012/05/08   10:0:4.04
-50.62596160,  67.01225911, 82.952, 2012/05/08   10:0:5.04

这是完整的程序(下)。它包含几个 if 语句。我试着把

printf( "Longitude, Latitude, Elevation , UTC Time\n");

在两个 if 语句之前,但我得到了相同的结果,每行都有四个单词的标题,而不是顶部的一行。

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include "applanix_data.h"
#include "applanix_pos_out.h"

#define DEGREES2RADIANS  (3.141592654 / 180.0)

int output_group_1(FILE *fp,
               FILE *fpout,
               unsigned short myyear,
               unsigned short mymonth,
               unsigned short myday,
               double time_sod,
               double double_time_met)
{
struct applanix_data_group1 data1;
struct pospacsbet sbet;

  if(fread(&data1,sizeof(struct applanix_data_group1),1,fp)==1)
 {
    sbet.gpstime = time_sod;
    sbet.latitude = data1.latitude * DEGREES2RADIANS;
    sbet.longitude = data1.longitude * DEGREES2RADIANS;
    sbet.altitude = data1.altitude;
    sbet.x_velocity = data1.eVelocity;
    sbet.y_velocity = data1.nVelocity;
    sbet.z_velocity = data1.dVelocity;
    sbet.roll = data1.aircraftRoll * DEGREES2RADIANS;
    sbet.pitch = data1.aircraftPitch * DEGREES2RADIANS;
    sbet.platform_heading = data1.aircraftHeading * DEGREES2RADIANS;
    sbet.wander_angle = data1.aircraftWanderAngle * DEGREES2RADIANS;
    sbet.x_body_acceleration = data1.aircraftTransverseAcceleration;
    sbet.y_body_acceleration = data1.aircraftLongitudinalAcceleration;
    sbet.z_body_acceleration = data1.aircraftDownAcceleration;
    sbet.x_body_angular_rate = data1.aircraftAngularRateAboutDownAxis;
    sbet.y_body_angular_rate = data1.aircraftLongitudinalAcceleration;
    sbet.z_body_angular_rate = data1.aircraftAngularRateAboutDownAxis;

    if(fwrite(&sbet,sizeof(struct pospacsbet),1,fpout)!=1)
      {
         fprintf(stderr,"Error writing POSPAC SBET output!\n");
         exit(-2);
      }

    sbet.latitude1 = sbet.latitude * (180/3.141592654);
    sbet.longitude1 = sbet.longitude * (180/3.14592654);
    sbet.day = sbet.gpstime/86400;
    sbet.time = sbet.gpstime/86400;
    sbet.hour1 = (sbet.time - sbet.day);
    sbet.hour = sbet.hour1*24;
    sbet.time = sbet.hour1*24;
    sbet.minute1 = (sbet.time - sbet.hour);
    sbet.minute = sbet.minute1*60;
    sbet.time = sbet.minute1 * 60;
    sbet.second1 = (sbet.time - sbet.minute);
    sbet.second = sbet.second1*60;

    printf("%12.8f, %12.8f, %6.3f, %04u/%02u/%02u   %i:%i:%4.2f\n",sbet.longitude1,sbet.latitude1,sbet.altitude,myyear,mymonth, myday, sbet.hour, sbet.minute, sbet.second);
    return 0;
 }
  else
 return -1;
}

我这样调用函数

unix> gcc -o applanixraw2out applanixraw2out.c

unix> ./applanixraw2out applanix_raw_20120508.bin > test.txt

4

4 回答 4

3
printf("Longitude,   Latitude,   Elevation,   UTC Time\n");
于 2013-08-27T13:54:18.270 回答
0
printf("Longitude, Latitude Elevation, UTC Time"\n);
于 2013-08-27T13:54:33.217 回答
0

看看我的简单库 libTprint:https ://github.com/wizzard/libtprint ,它完全符合您的要求。看一下代码——它很简单,你应该能够理解它是如何工作的。

希望能帮助到你 !

于 2013-08-27T22:53:23.910 回答
0

之前if(fread ...,使用格式化的标题

printf("%-12s, %-12s, %-6s, %-12s\n", "Longitude", "Latitude", "Elevation", "UTC Time");

然后,您可以轻松调整间距以匹配您的大部分

printf("%12.8f, %12.8f, %6.3f ...
于 2013-08-27T15:07:37.053 回答