this question answered. nothing formatters instead idiocy when comes copying new buffers.
i'm hoping 1 line answer. have snprintf()
statement following:
snprintf(buffer, sizeof(buffer), "%03d", 0u);
i'm expecting buffer
hold 000
reason holds 00
. assume buffer plenty large enough hold want. being silly?
edit:
see below complete code context. trying simplify before didn't think context necessary. point still remains, using %04u
gives me 000
in first csv row. %03u
gives me 00
.
uint16_t csvgenerator::write_csv_data(testrecord* record) { // define templates. const char *row_template = "%04u,%6.3e,%6.3e,%6.3e,%6.3e,%6.3e\n"; char csv_row_buffer[csv_row_buffer_size]; // add data. uint16_t row_count = 0u; (uint16_t reading = 0u; reading < measure_reading_count; ++reading) { // parse row. snprintf(csv_row_buffer, sizeof(csv_row_buffer), row_template, // test id measure_period_secs * reading, // impedances z1-z5. record->measurements[reading][0u], record->measurements[reading][1u], record->measurements[reading][2u], record->measurements[reading][3u], record->measurements[reading][4u]); // add main buffer, excluding terminator. strncpy((m_csv_data_buffer + (reading * csv_row_buffer_size) - 1u), csv_row_buffer, (sizeof(csv_row_buffer) - 1u)); // increment row count. ++row_count; } // : each reading. return row_count; }
how check contains "000"? if reading (m_csv_data_buffer + (reading * csv_row_buffer_size))
losing first byte since you've copied (m_csv_data_buffer + (reading * csv_row_buffer_size) - 1u)
in code.
Comments
Post a Comment