in Education by
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)

1 Answer

0 votes
by
When you use name as the first value in the initializer of an Artist, you're trying to store a pointer in a char array. That's an invalid initializer. You need to set those fields explicitly: Artist newArtist(char name[], int accountNum, double accountBal, char tele[], double earningPerYr) { Artist tempArtist = {"", accountNum, accountBal, "", earningPerYr }; strcpy(tempArtist.realName, name); strcpy(tempArtist.telephoneNumber, tele); return tempArtist; }

Related questions

0 votes
    I have an issue with passing a struct definition to a function. Not an instance of a struct, but the definition. We ... (object sender, EventArgs e) { GetHeaders( MineStruct ); //...
asked May 26, 2022 in Education by JackTerrance
0 votes
    I am getting the error 'Uncaught TypeError: firebase.auth is not a function'. My code was working perfectly ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 14, 2022 in Education by JackTerrance
0 votes
    ______________ is populating the inbox of any target victim with unsolicited or junk emails. (a) Phishing (b ... -Cyber Security:,Cyber Security-Jobs:,Cyber Security Applications...
asked Oct 31, 2021 in Education by JackTerrance
0 votes
    In my application, I'm displaying a Power BI report. It already works, so there's no problem with showing ... dataset in the report? Select the correct answer from above options...
asked Feb 4, 2022 in Education by JackTerrance
0 votes
    What are the different ways of passing parameters to the functions? Which to use when?...
asked Jan 18, 2021 in Technology by JackTerrance
+1 vote
    What are the different ways of passing parameters to the functions in C Programming? Which to use when?...
asked Nov 9, 2020 in Technology by JackTerrance
0 votes
    I posted this : PHP 5.2.x: $_POST is empty when any field has value of "drop anywords from ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Feb 19, 2022 in Education by JackTerrance
0 votes
    It is a peripheral device which will print anything created on a computer onto a paper, whether it be text or ...  Projector  Monitor Select the correct answer from above options...
asked Dec 24, 2021 in Education by JackTerrance
0 votes
    This question already has answers here: JavaScript: Difference between .forEach() and .map() (15 answers) ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 7, 2022 in Education by JackTerrance
0 votes
    If 10 objects are distributed at random among 10 persons, then find the probability that at least one of them will ... . none of these Select the correct answer from above options...
asked Nov 15, 2021 in Education by JackTerrance
0 votes
    I have an graphql/apollo-server/graphql-yoga endpoint. This endpoint exposes data returned from a database ( ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked May 7, 2022 in Education by JackTerrance
0 votes
    Is it possible to pass a function/callback from javascript to a java applet? For example i have an ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 17, 2022 in Education by JackTerrance
0 votes
    Is it possible to pass a function/callback from javascript to a java applet? For example i have an ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 17, 2022 in Education by JackTerrance
0 votes
    Is it possible to pass a function/callback from javascript to a java applet? For example i have an ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 17, 2022 in Education by JackTerrance
...