Question
This is C programming. Please help me understand this code: The more detail, the better. Thank you so much: #include #include #include #include io.h #include
This is C programming. Please help me understand this code: The more detail, the better. Thank you so much:
#include
#include
#include
#include "io.h"
#include "stats.h"
#include "utils.h"
#include "common.h"
int main(int argc, char* argv[])
{
int size = 0;
char **files_list = (char **) malloc (sizeof (char*) * 100);
//FILE is the structure's name, fp is declared as FILE pointer type
FILE *fp;
char *fileName;
int outputFile = 0;
//get_reg_files_list2(argv[1], &files_list, &size);
//printf("There are %d regular files in %s ", size, argv[1]);
//print_strings(stdout,files_list, size);
int num = 1;
int count = 0;
char str_delim = ',', ffname[256];
while ( num <= argc - 1 )
{
if (! strcmp(argv[num], "-o" ))
{
outputFile = 1;
fileName = argv[num+1];
fp = fopen(fileName, "a");
num = num + 1;
}
else
{
files_list[count] = (char *) malloc (sizeof (char) * 15);
strcpy(files_list[count], argv[num]);
count++;
}
num++;
}
num = 0;
//snprintf(ffname, sizeof(ffname)-1, "%s%s", argv[1], files_list[1]);
while ( num < count ) // argc - totla number of arguments including the executable name.
{
//ffname will be ../../data/stocks/argv[num]
// Will change for each iteration of the loop.
snprintf(ffname, sizeof(ffname) -1, "../../data/stocks/%s", files_list[num]); // argv[num] - argument.
Corporation *corp = (Corporation *)malloc(sizeof(Corporation));
get_stock_values(ffname, &(corp->data), &(corp->date), str_delim, &corp->data_rows, &corp->data_cols);
//get_stock_values(ffname, &(corp->summary_quote), &(corp->date), str_delim, &corp->data_rows, &corp->data_cols);
corp->date_length = corp->data_cols;
printf("File %s has %d rows and %d cols of data ", ffname, corp->data_rows, corp->data_cols);
// these are fake values
strcpy(corp->name, "Cecilia");
strcpy(corp->ticker, "abc");
strcpy(corp->industry, "computers");
strcpy(corp->sector, "electronics");
corp->stats = (Stats *) malloc(corp->data_rows*sizeof(Stats));
get_all_stats(corp->stats, corp->data, corp->data_rows, corp->data_cols);
print_stats_table(stdout, corp);
if ( outputFile )
{
print_stats(fp, corp->stats);
}
num++;
}
fclose(fp);
return EXIT_SUCCESS;
}
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started