subject

#include #include #include #define MAX_LENGTH 100 typedef struct Input Input; struct Input { int num1; int num2; int num3; }; void getInputValuesFromString(char string[], Input *inputValues); /* * Programming Assignment 2 */ int main(int argc, char** argv) { // IMPORTANT: Only add code in the section // indicated below. The code I've provided // makes your solution work with the // automated grader on Coursera char input[MAX_LENGTH]; fgets(input, MAX_LENGTH, stdin); while (input[0] != 'q') { Input inputValues; getInputValuesFromString(input, &inputValues); // Add your code between this comment // and the comment below. You can of // course add more space between the // comments as needed // Don't add or modify any code below // this comment fgets(input, MAX_LENGTH, stdin); } return 0; } /* * Extracts input values from provided string */ void getInputValuesFromString(char string[], Input *inputValues) { // find first space index int spaceIndex = -1; char *result = NULL; result = strchr(string, ' '); char *stringStart = &string[0]; spaceIndex = result - stringStart; // extract first number from string char* firstNumberString = malloc((spaceIndex + 1) * sizeof(char)); strncpy(firstNumberString, string, spaceIndex); firstNumberString[spaceIndex] = '\0'; inputValues->num1 = atoi(firstNumberString); // find second space index string = &string[0] + spaceIndex + 1; result = strchr(string, ' '); stringStart = &string[0]; spaceIndex = result - stringStart; // extract second number from string char* secondNumberString = malloc((spaceIndex + 1) * sizeof(char)); strncpy(secondNumberString, string, spaceIndex); secondNumberString[spaceIndex] = '\0'; inputValues->num2 = atoi(secondNumberString); // extract third number from string string = &string[spaceIndex + 1]; inputValues->num3 = atoi(string); // free memory free(firstNumberString); firstNumberString = NULL; free(secondNumberString); secondNumberString = NULL; }

ansver
Answers: 2

Another question on Computers and Technology

question
Computers and Technology, 21.06.2019 15:30
Which function in spreadsheet software can be used to predict future sales or inventory needs?
Answers: 2
question
Computers and Technology, 22.06.2019 17:30
Type the correct answer in the box. spell all words correctly. under which key category do the page up and page down keys fall? page up and page down keys fall under the keys category.
Answers: 3
question
Computers and Technology, 23.06.2019 02:30
What is the power dissipated by a resistor with a current of 0.02 a and a resistance of 1,000 ? a. 200 w b. 20 w c. 0.4 w d. 4 w
Answers: 1
question
Computers and Technology, 23.06.2019 13:30
Select the correct answer from each drop-down menu. which types of computer networks are bigger as well as smaller than a man? a man is a network of computers that covers an area bigger than a , but smaller than a .
Answers: 1
You know the right answer?
#include #include #include #define MAX_LENGTH 100 typedef struct Input Input; struct Input { int num...
Questions
question
Mathematics, 13.11.2019 08:31
question
Mathematics, 13.11.2019 08:31