Struct? Class? #13

Closed
opened 2018-11-02 21:33:37 +00:00 by Squatnet · 5 comments
Squatnet commented 2018-11-02 21:33:37 +00:00 (Migrated from github.com)

This is a place for me to write pseudocode relatg to building a system to store and recover devices registered on pjon network

int id = 3;
char * name = "Hello";

struct device {
   int id;
   char * name;
   };
device devA=  {3, "HELLO"};
device devB = {2, "hi"};
devA.id = 5;
device devC ={ (devB.id+devA.id) , (devA.name+" - "+devB.name)}
This is a place for me to write pseudocode relatg to building a system to store and recover devices registered on pjon network ``` int id = 3; char * name = "Hello"; struct device { int id; char * name; }; device devA= {3, "HELLO"}; device devB = {2, "hi"}; devA.id = 5; device devC ={ (devB.id+devA.id) , (devA.name+" - "+devB.name)} ```
Squatnet commented 2018-11-03 01:49:25 +00:00 (Migrated from github.com)

interesting
ure, you'd write it like this:

#include <string>
#include <vector>

struct MYStruct
{
     std::vector<std::string> str;
     int num;
};

MyStruct const data[] = { { { "Hello", "World" }, 1 }
                        , { { "my other string" }, 3 }
                        };

Unless I'm misunderstanding and you actually just want num to count the number of elements. Then you should just have:


std::vector<std::string> data[] = { { "Hello" }
                                  , { "my", "other", "string" }
                                  };

And you can recover the element sizes with data[0].size(), data[1].size(), etc.

interesting ure, you'd write it like this: ``` #include <string> #include <vector> struct MYStruct { std::vector<std::string> str; int num; }; MyStruct const data[] = { { { "Hello", "World" }, 1 } , { { "my other string" }, 3 } }; ``` Unless I'm misunderstanding and you actually just want num to count the number of elements. Then you should just have: ``` std::vector<std::string> data[] = { { "Hello" } , { "my", "other", "string" } }; ``` And you can recover the element sizes with `data[0].size(), data[1].size(), `etc.
Squatnet commented 2018-11-03 02:05:29 +00:00 (Migrated from github.com)

Also looks helpful

#include <iostream>
#include <cstring>

using namespace std;

struct student
{
	int roll_no;
  	string name;
  	int phone_number;
};

void display(struct student st)
{
  	cout << "Roll no : " << st.roll_no << endl;
  	cout << "Name : " << st.name << endl;
  	cout << "Phone no : " << st.phone_number << endl;
}

int main(){
	struct student s;
  	s.roll_no = 4;
  	s.name = "Ron"; 
  	s.phone_number = 888888;
  	display(s);
	return 0;
}
Also looks helpful ``` #include <iostream> #include <cstring> using namespace std; struct student { int roll_no; string name; int phone_number; }; void display(struct student st) { cout << "Roll no : " << st.roll_no << endl; cout << "Name : " << st.name << endl; cout << "Phone no : " << st.phone_number << endl; } int main(){ struct student s; s.roll_no = 4; s.name = "Ron"; s.phone_number = 888888; display(s); return 0; } ```
Riolaurenti commented 2018-11-03 08:26:06 +00:00 (Migrated from github.com)

That last example makes it SO much clearer!

On Sat, Nov 3, 2018 at 2:05 AM Squatnet notifications@github.com wrote:

Also looks helpful

#include
#include

using namespace std;

struct student
{
int roll_no;
string name;
int phone_number;
};

void display(struct student st)
{
cout << "Roll no : " << st.roll_no << endl;
cout << "Name : " << st.name << endl;
cout << "Phone no : " << st.phone_number << endl;
}

int main(){
struct student s;
s.roll_no = 4;
s.name = "Ron";
s.phone_number = 888888;
display(s);
return 0;
}


You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
https://github.com/Squatnet/ArduinoStuff/issues/13#issuecomment-435552413,
or mute the thread
https://github.com/notifications/unsubscribe-auth/AV5OqxQAXA0QZa8ppoMkjW4DzH2th2NIks5urPnqgaJpZM4YMaB9
.

That last example makes it SO much clearer! On Sat, Nov 3, 2018 at 2:05 AM Squatnet <notifications@github.com> wrote: > Also looks helpful > > #include <iostream> > #include <cstring> > > using namespace std; > > struct student > { > int roll_no; > string name; > int phone_number; > }; > > void display(struct student st) > { > cout << "Roll no : " << st.roll_no << endl; > cout << "Name : " << st.name << endl; > cout << "Phone no : " << st.phone_number << endl; > } > > int main(){ > struct student s; > s.roll_no = 4; > s.name = "Ron"; > s.phone_number = 888888; > display(s); > return 0; > } > > — > You are receiving this because you are subscribed to this thread. > Reply to this email directly, view it on GitHub > <https://github.com/Squatnet/ArduinoStuff/issues/13#issuecomment-435552413>, > or mute the thread > <https://github.com/notifications/unsubscribe-auth/AV5OqxQAXA0QZa8ppoMkjW4DzH2th2NIks5urPnqgaJpZM4YMaB9> > . >
Squatnet commented 2018-11-03 19:35:54 +00:00 (Migrated from github.com)

Exactly what i thought. Very clear and seems like exactly what we need to be doing.

Exactly what i thought. Very clear and seems like exactly what we need to be doing.
Squatnet commented 2018-11-06 21:55:28 +00:00 (Migrated from github.com)

As using

struct device { 
    int id;
    char name;
   };
device strips[100];
device matrix[20];

and then calling strips[2].id seems to work fine now i'm closing this

As using ``` struct device { int id; char name; }; device strips[100]; device matrix[20]; ``` and then calling `strips[2].id` seems to work fine now i'm closing this
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
squatnet/ArduinoStuff#13
No description provided.