Question: I need help fixing and implementing my function into my project. I'm trying to make it where you can enter multiple things in the code

I need help fixing and implementing my function into my project. I'm trying to make it where you can enter multiple things in the code to get different results.

Ex

./stocks.x will do the entire program

./stocks.x 12 will now how many stocks there is already and just ask for the price and give the results

./stocks.x 12 2,3,4,5,6,7,8,77 will already know the stocks and the price and just give the results but will take out the , token

./stocks.x 12 4 4 68 7 5 3 7 will already know the stocks and the price and just give the results

To be clear I can not use some use commands like malloc, etc.. I can only use strings, pointers, and argc and argv

I need this implemented in stocks.c

I need help fixing and implementing my function into my project. I'm

here is the algorithm to use

trying to make it where you can enter multiple things in the

Here what I need done. the other files that are not shown are completly fine

stocks.c

#include

#include

#include "utils.h"

#include "io.h"

#include "stats.h"

int main(int argc, char* argv[])

{

int size, i;

char order;

float *array;

//if user enters only ./stocks.x

if

{

// greet and get the number of stocks

print_greeting();

printf("How many stocks prices would you like to analyze? ");

scanf("%d", &size);

// read the data

float array[size];

read_array(array, size);

}

// if user enters only ./stocks.x and a number

else if

{

printf("How many stocks prices would you like to analyze? ");

scanf("%d", &size);

// read the data

float array[size];

read_array(array, size);

}

else if

{

// user enters a coma between numbers

//util function goes here go here

// read the data

float array[size];

read_array(array, size);

}

else

{

// user enters ./stocks.x and numbers with spaces

float array[size];

read_array(array, size);

}

// get the stats

float mean = get_average(array, size);

float variance = get_variance(array, size);

float min = get_min(array, size);

float max = get_max(array, size);

float median = get_median(array, size);

// show the results

print_results(array, size, median, min, max, mean, variance);

return 0;

}

utils.h

#ifndef UTILS_H #define UTILS_H

int get_num_tokens(const char str[], char delim); void get_tokens_array(const char str[], float array[], float size, char delim);

#endif

utils.c

#include #include #include #include "utils.h"

int get_num_tokens(const char str[], char delim)

{

int i = 0,count = 1;

while (str[i] != '\0')

{

if (str[i++] == delim)

count++;

}

return count;

}

void get_tokens_array(const char str[],float array[], float size, char delim)

{

char *input = const_cast(str);

char *d = &delim;

char *token = strtok(input, d);

int i = 0;

while (token != NULL)

{

printf(" token # %d is %s ", i+1, token);

array[i++] = atof(token);

token = strtok(NULL, d);

}

size = i;

}

5. add a function called int get num.tokens(const char strll, char delim): This is a utility function that counts the number of tokens in a string given a delimiter. 6. add a function called void get tokens array(const char strl, float arrayll. float size, char delim); This is a utility function that breaks up the string tokens for a given delimiter and assigns the tokens to an array of floats. 7. (optional) add a function called bool has.delim(const char strl, char delim); this is utilities function that checks to see if a string has a given token. Alternatively you can use strchr function in string.h to do the same thing. 8. If you need to copy a string, create a temporary string of size 1024 or 2948 characters and copy the original string into this temporary string using the strcpy function fom string.h Do not use the pow function or any other mathematical functions Use any looping construct you like.Also don't use pointers or dy- namic memory allocation or global variables

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!