- To asign a char value into the struct 'field', I have to use strcpy ?
I tried this:
struct student{ char name[50]; int age; }; int main(){ struct student std; std.name = "john"; //Doesnt work strcpy(std.name, "john"); //It DOES work std.age = 20; return 0;} Why when comes to char I can not simply use the ' = ' to assign a value ?
How may I pass a struct initialized in main(){} as a parameter to a function and change it's values inside the function without the need of a return. Do I just use the '*' like:
void MyFunction(struct student *std){ std->Name = "John"; std->Age = 20; } int main(){ struct student me; Myfunction(me); }
Is that the correct way to do so ?