Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Modify the attached file. Your C 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

csv.c file contains the code below:

#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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Practical Oracle8I Building Efficient Databases

Authors: Jonathan Lewis

1st Edition

0201715848, 978-0201715842

More Books

Students also viewed these Databases questions

Question

what is the effective annual rate of 12% compounded semiannually

Answered: 1 week ago