Answer to Question #257362 in C for tom

Question #257362

Write a C program which reads and access the elements of the csv file by using the system call functions such as read, write and open. You should sum all the no. present inside a particular column in that csv file . by using the system call functions.


1
Expert's answer
2021-10-28T01:59:21-0400
#include <stdio.h>


#include <stdlib.h>


int main()


{


int sum=0;


FILE *myFile;


myFile = fopen("number.csv", "r");






int numberArray[10];


int i;


if (myFile == NULL)


{


printf("Error Reading File\n");


exit (0);


}


for (i = 0; i < 10; i++)


{


fscanf(myFile, "%d,", &numberArray[i] );


}


for (i = 0; i < 10; i++)


{


sum=sum+(numberArray[i]);


}


fclose(myFile);


printf("Sum is: %d\n\n", sum);


return 0;


}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS