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, 22.06.2019 11:50
You have written, as part of a school assignment, a research paper on the solar system. you want to share this paper on your school website. on which type of server will you upload it?
Answers: 1
question
Computers and Technology, 23.06.2019 12:30
What is the difference between the internet and the world wide web?
Answers: 1
question
Computers and Technology, 23.06.2019 15:00
To check whether your writing is clear , you can
Answers: 2
question
Computers and Technology, 24.06.2019 00:30
Use the keyword strategy to remember the meaning of the following word. the meaning for the word has been provided. write your keyword and describe the picture you would create in your mind. obfuscate: to make something so confusing that it is difficult to understand.
Answers: 2
You know the right answer?
#include #include #include #define MAX_LENGTH 100 typedef struct Input Input; struct Input { int num...
Questions
question
Mathematics, 05.12.2019 03:31
Questions on the website: 13722363