Question

In: Computer Science

Hi guys, I need someone to look over a some codes. My xcoder telling I have...

Hi guys,

I need someone to look over a some codes. My xcoder telling I have error(s), and I need someone to look what causing these errors.

I'm leaving the codes that are giving me errors. I don't want to give my whole code away for privacy reasons. Language is C

1.

#include

#include

#include

#define MAXCHAR 50

/*Here are the structs for the monsters, regions, and commonality.*/

/*typedef struct was provide in instruction*/

typedef struct monster{

int id;

char *name;

char *element;

int popultaion;

}monster;

typedef struct region{

char *name;

int nmonsters;

int total_population;

monster **monsters;

}region;

typedef struct itinerary{

int nregion;

region **region;

int captures;

}itinerary;

typedef struct trainer{

char *name;

itinerary *visits;

}trainer;

/*Monster fill informations. Constructor. */

monster* newCreate( char *name, int popultaion, char *element){

      int gameNam, loveGame;

/*Assigns string to a variable for ease of use.*/

   gameNam = strlen(gameNam) + 1; <------------Here is my error

   loveGame = strlen(loveGame) + 1;<------------Here is my error

   /*Malloc new space.*/

monster *newCreature = (struct monster*)malloc(sizeof(struct monster));

newCreature->name = (char*)malloc(gameNam * sizeof(char));

newCreature->element = (char*)malloc(loveGame * sizeof(char));

/*All struct values will be assigned*/

strncpy(newCreature->name, name, gameNam);

strncpy(newCreature->element, element,loveGame);

newCreature->popultaion = popultaion;

return newCreature;

}

2.

monster** readCreatures(FILE* inFile, int *numbers){

monster **createL, *monster;

char name[MAXCHAR], element[MAXCHAR];

int population;

fscanf(inFile, "%d%*s", numbers);

createL = (struct monster**)malloc(*numbers * (sizeof(struct monster)));

/*This will allow the list to be filled.*/

for(int i=0; i < * numbers; i++){

fscanf(inFile, "%s %s %d", name, element, &population);

creatureList[i] = createL(name, element, population);<------------Here is my error

}

return createL;

}

------------------------

Input file:

8 monstersStAugustine

Grass 12

Zoysia Grass 8

WholeWheat Bread 6

MultiGrain Bread 10

Rye Bread 10

Cinnamon Spice 5

Pepper Spice 10

Pumpkin Spice 303 regions

Rome4 monsters

Solutions

Expert Solution

The errors in the code provided above are due to follwoing reasons:

Error 1 and Error 2:

gameNam = strlen(gameNam) + 1; <------------Here is my error

loveGame = strlen(loveGame) + 1;<------------Here is my error

These both are errors due to the same reason

that both variables used are integer

int gameNam, loveGame;

Now we have used strlen function

so first check syntax of strlen function is

size_t strlen( const char* str );

which we can clearly see takes as arguement as character pointer or a string

and returns size_t which is a integer

Probable Error if int is passed instead of char *

initializing argument 1 of 'size_t strlen(const char*)'
extern size_t strlen (const char *__s)

Mistake:

and you have used as parameter gameNam and loveGame which are both integer thus this will give you error as this will not be found

so character pointer or string should be passed as parameter

I think in the function char *name is passed as parameter so according to your logic modify code

and it could be used as

gameNam = strlen(name) + 1;

which will give length of name added to 1 so name="abcd"

gameNam woud be 4+1=5

For error 3

creatureList[i] = createL(name, element, population);<------------Here is my error

Mistake:

The reason of error is that for the file you have not done error checking procedure while taking from file that is the number present in file or not and for that also check defination of  createL defination. For privacy reason as you have not uploaded full solution so please check for signature of class.

Like in last line Rome4 monsters can cause error if not extrcted properly

like is the parameter order same with correct type and defination also implement error checking while extracting input form the file

Hope you are able to understand the concepts and remove errors


Related Solutions

I have this question in my nursing class I just need someone to answer it for...
I have this question in my nursing class I just need someone to answer it for me Reflect on an occasion where you experienced ineffective leadership (doesn't have to be in the hospital/healthcare). What behaviors did they display? What factors may have influenced their leadership style?
I have bolded the answers I chose. I just need someone to check my work and...
I have bolded the answers I chose. I just need someone to check my work and if I'm wrong possibly explain why, please? 1. If a stock pays a dividend, the owner of a call option will see the value of their option decrease by the amount of that dividend payment. a. true b. false 2. DEF stock currently trades for $40. Both American calls and puts are available on the stock. All else being constant, which of the following...
Hi, I have some doubs about answers to following questions and I apprecite if someone could...
Hi, I have some doubs about answers to following questions and I apprecite if someone could help me with the answers: We want to investigate the following research problem: We have been developing a new learning and teaching application and want to know if this application is more efficient on a tablet or on a mobile phone. Efficiency is measured in the speed in which answers in the form of text are entered. i. Formulate the hypothesis H1 and the...
Java Program to Fully Parenthesize an expression. Hi guys. I have a small task which I...
Java Program to Fully Parenthesize an expression. Hi guys. I have a small task which I cannot find the solution for. It involves expressions with Infix I'll need a Java Program to convert an expression, eg. 3+6*(x-y)+x^2 to ((3 + (6 * (x-y))) + (x ^ 2)) Kindly assist. Thanks
Hi I need some ideas for creating four different regression models. My dependent variable is GDP...
Hi I need some ideas for creating four different regression models. My dependent variable is GDP and my independent variables are state (which includes all 50 states including D.C.), year (which includes the years 2016-2018), agedpop (if the population is 65 or older). WestCoast (=1 if the state is on the west coast and 0 if not). EastCoast (=1 if the state is on the east coast and 0 if not), and Midwest (=1 if the state is in the...
Hi guys, I'm working on an assignment for my Java II class and the narrative for...
Hi guys, I'm working on an assignment for my Java II class and the narrative for this week's program has me a bit lost. I've put the narrative of the assignment in the quotation marks below. " Included with this assignment is an encrypted text file. A simple Caesar cipher was used to encrypt the data. You are to create a program which will look at the frequency analysis of the letters (upper and lowercase) to help “crack” the code...
My Teacher keeps telling me I don't have a Thesis. I thought I hada good thesis....
My Teacher keeps telling me I don't have a Thesis. I thought I hada good thesis. Please help! Bud Light in advertising             One of the most effective ways for businesses to thrive is to use effective advertising, whether the ad is on TV, magazines, social media or even movies. The goal is to create enticement for a purchase over the competitor’s product. Budweiser is great example of a billion dollar company that has always maintained a strong record of...
YOU GUYS PROVIDE ME THE WRONG ANSWER SO I NEED THE CORRECT ANS Check my work...
YOU GUYS PROVIDE ME THE WRONG ANSWER SO I NEED THE CORRECT ANS Check my work Check My Work button is now enabledItem 4 Item 4 30 points A private not-for-profit entity is working to create a cure for a deadly disease. The charity starts the year with cash of $775,000. Of this amount, unrestricted net assets total $425,000, temporarily restricted net assets total $225,000, and permanently restricted net assets total $125,000. Within the temporarily restricted net assets, the entity...
I need a care plan for COPD. In this care plan i need you guys to...
I need a care plan for COPD. In this care plan i need you guys to include nursing diagnosis for COPD. Then 6 short term and 6 long term goals for COPD. I need one nursing intervention for each each short term and each long term goal. And the evaluation for each nursing intervention. Please give me something creative THANK YOU!
Hi, I am struggling to understand this worksheet my professor gave us for practice. Could someone...
Hi, I am struggling to understand this worksheet my professor gave us for practice. Could someone make any sense of this? The scenario: Sodium is found largely in the extracellular compartment with concentrations between 130-145 mM with intracellular sodium concentrations between 3.5-5mM. This chemical difference gives sodium a large concentration gradient, which when permitted (by opening of a channel or through facilitated transport) will move down its concentration gradient to enter the cell. Sodium also has a favorable electrical gradient;...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT