I have a structure with a string defined inside it, is there a way to change the string later in my program....
CODE....
//define structure
struct myStruct {
char name[40];
int age;
};
//function to fill array of structures with values
void fillArray(struct myStruct *);
int main(void){
//create array of structs
struct myStruct myStructArray[10];
//put values in array of structs
fillArray(&myStructArray);
//print name from struct
printf("%s", myStructArray[2].name);
}
//fills array with values
void fillArray(struct myStruct * workwithStruct){
workwithStruct[2].name = "JOHN";
return;
}
if i print the name inside the fillArray function it will print fine but when I return to the main function it prints garbage
I'm new to structs, Can someone please help me out?



LinkBack URL
About LinkBacks


