I'm trying to make a function in c to create and return a new struct similar to a constructor in OOP. When checking the variables the string is junk while the numbers are all 0. Can structs not be initialized using variables in c?
I've looked online for people who are trying a similar thing but they all use literals and strings to initialize theirs.
typedef struct tArtist{
char realName[20];
int accNum;
double accBal;
char telephoneNumber[15];
double earningPerYear;
} Artist;
...
//function call
Artist artist = newArtist("Real Name", 123, 600.43, "1-(876)-362-2335", 999.99);
Artist newArtist(char name[], int accountNum, double accountBal, char tele[], double earningPerYr) {
Artist tempArtist = {name, accountNum, accountBal, tele, earningPerYr };
return tempArtist;
}
I expected as a test the realName to be "real name" but got X{XRc
JavaScript questions and answers, JavaScript questions pdf, JavaScript question bank, JavaScript questions and answers pdf, mcq on JavaScript pdf, JavaScript questions and solutions, JavaScript mcq Test , Interview JavaScript questions, JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)