Question: Modify the attached file. Your program shall read lines from the command line until a blank line is entered. The program shall split each line

Modify the attached file. Your program shall read lines from the command line until a blank line is entered. The program shall split each line into comma-separated columns. Each fully-numeric column field shall be converted to a number, and the mean of all numeric fields shall be calculated. The program then shall construct a string that contains the original column fields, separated by single commas. However, each non-fully-numeric field (e.g., "123%" or "n/a") shall be replaced with "NULL" (less the quotes). The mean value of all numeric fields, as calculated before, shall be appended to the end of the string after a comma. If the string has no numeric fields, the mean value shall be set to NULL (less the quotes). The constructed string shall be printed on a separate line. Consider the following examples:

USER> 1,2,3,1.5,hello,2,world! PROGRAM> 1,2,3,1.5,NULL,2,NULL,1.9 USER> No, I do not PROGRAM> NULL,NULL,NULL

The code given

#include  #include  #include  #define ROW_SIZE 1024 #define SEP "," int main() { char row[ROW_SIZE]; fgets(row, sizeof row, stdin); // Count the columns int n_commas = 0; for(int i = 0; i < strlen(row); ++i) if(row[i] == SEP[0]) n_commas++; // Extract the columns char *columns[n_commas + 1]; char *source = row; int n_columns = 0; while((columns[n_columns++] = strtok(source, SEP))) { source = NULL; } n_columns--; // INSERT YOIR CODE HERE return 0; }

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!