Skip to content

Struct with a char[] #32

Answered by rlogiacco
BenWeinberg asked this question in Q&A
May 18, 2020 · 7 comments · 1 reply
Discussion options

You must be logged in to vote

And just for completeness, this is the same but without using dynamically allocated memory:

#include <CircularBuffer.h>

namespace data {
	typedef struct {
		char time[2];
		unsigned int value;
		bool flag;
	} record;
	void print(record r) {
		Serial.print(r.time[0]);
		Serial.print(r.time[1]);
		Serial.print("	");
		Serial.print(r.value);
		Serial.print("	");
		Serial.print(r.flag);
	}
}

CircularBuffer<data::record, 10> structs;
#define SAMPLE_PIN A0

void setup() {
	Serial.begin(9600);
	while (!Serial);
	Serial.println("STARTING UP");
}

void generate(char p[], uint len) {
	for (int i = 0; i < len; i++) {
		p[i] = char(random(65, 122));
	}
}

void loop() {
	unsigned int sample = analog…

Replies: 7 comments 1 reply

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Answer selected by rlogiacco
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
1 reply
@clearbucketLabs
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants
Converted from issue

This discussion was converted from issue #32 on December 12, 2020 14:17.