Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write the following functions: int readCdData (char fileName [], char csvMatrix

ID: 3801678 • Letter: W

Question

Write the following functions: int readCdData (char fileName [], char csvMatrix [] [MAX_STR_LEN]) This function open the file specified by the fileName [] string and reads all the lines, storing them in csvMatrix. It also returns the total number of lines read. void stripNewLineAtEOS (char str []) If the last character in str [] is the nee line character, this function removes it by replacing it with '' void get substring (char str [], int il, int i2, char substr []) Extracts a substring substr [] from (the larger) string str [] from index il to 12 - 1; that is, i2 is one past the index of last character to put into the substring.

Explanation / Answer

HI, Please find my implemntation of all methods.

Please let me know in case of any issue.


int readCdData(char fileName[], char csvMatrix[MAX_STR_LEN]){
  

FILE * fp;
char * line = NULL;
size_t len = 0;
int count = 0;

fp = fopen(fileName, "r");
if (fp == NULL)
return count;

while ((read = getline(&line, &len, fp)) != -1) {
   strcpy(line, csvMatrix[count++]);
}

fclose(fp);
  
return count;
}


void stripNewLineAtEOS(char str[]){
  
   int i=0;
   while(str[i] != ''){
       if(str[i] == EOF){
           str[i] = '';
           return;
       }
   }
}


void getSubstring(char str[], int i1, int i2, char substr[]){
  
   for(int i=i1, i<i2; i++)
       substr[i] = str[i];
   substr[i2] = '';
}