Quantcast
Channel: Arduino Forum - Latest topics
Viewing all articles
Browse latest Browse all 15346

Ways to access structs

$
0
0

Hi All
I am studying structs at the moment and according to the tutorial in the link below (from minute 14), there are a number of ways to access and modify structs.

https://www.youtube.com/watch?v=y4x3iyESFgs&list=PLfVsf4Bjg79CZ5kHTiQHcm-l2q8j06ofd&index=59)
however two of the ways he describe (the ones I have commented out) don't seem to work in arduino code. I just checking if this is normal or maybe I am missing something.

Also I am trying to use String instead of using a char array for the name type, but I get errors when using strcpy... yes I am aware that I can simply do clare.name = "Clare"; when using String rather than char but I wander... is strcpy only working with char arrays and not with strings ?? :thinking:

example:

struct students{		
char name[25];	
int age;		
int rollno;		
};

struct students john {"John", 24, 555};
struct students clare, bob;


// struct students mark { name : "Mark", age : 24, rollno : 566 };
// struct students mark { .name = "Mark", .age = 24, .rollno = 566 };


void setup() 
{
clare.age = 55;
strcpy(clare.name, "Clare");
}

void loop() {
}

11 posts - 3 participants

Read full topic


Viewing all articles
Browse latest Browse all 15346

Trending Articles